I was solving one of the leetcode problems(Longest Palindrome), where I am traversing the whole string(s) to count the frequency of each character traversing the array(charFreq) to determine whether the frequency of character is odd and doing operations accordingly. 1. Implementing using array where, 1 <= s.length <= 2000 s consists of lowercase and/or uppercase English letters only. But, is

# Tag: time-complexity

## What is the time complexity of HashMap insertion and retrieval inside of a for loop?

I have written this code for an application but I’m having difficulty figuring out if its better than the legacy code (legacy code used one hashmap with List in every value). From what I understand, since Java 8 the insertion and retrieval from a Hashmap is O(log n) and the for loop is O(n) in my case. Am I correct

## Is my Java solution O(n) or am I missing something?

My solution for a certain problem is apparently slower than 95% of solutions and I wanted to make sure that I was correct on the time complexity. It looks to me like this code is O(n). I use a couple of loops that are at most O(n) and they aren’t nested so I don’t believe the solution is n^2. I

## TapeEquilibrium, Solution Failing Two Edge Cases

Currently working on problems from codility for practice, and for some reason I’m unable to get more than 83% correctness overall, originally I solved it with 100% correctness but with N^2 time …

## Analysis of recursive approach for rotating an array of integers

While solving Array rotation on LeetCode, I wrote a recursive algorithm to solve the problem: Given an array, rotate the array to the right by k steps, where k is non-negative. Example 1: Input: nums …

## How to calculate the time complexity of this program? (Checking subarray in greater array)

Java program to check if an array is subarray of another array class // Function to check if an array is // subarray of another array static boolean isSubArray(int A[], int B[], …

## How is the ArrayList add(Type value) method O(1) amortized time complexity?

Most implementations of the ArrayList use an array internally and when the size is already exhausted upon adding an element to the list, it resizes or “grows” by essentially doing the …

## Analysis of run time complexity

I need some help below I have some code I created for an assignment. I am having a hard time figuring out the time complexity of this algorithm. I looked at it and believe the O-notation is 0(n) and …

## What is the time complexity of the following piece of code

int FindSum(int[] A, int[] B){ int[] temp = A; A = B; B = temp; } here in this java code we are swapping both the arrays, in this case only the memory reference of arrays is changing or …