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
what’s the growth order of “find a peak” algorithm
hello i need to apply an algorithm similar to this but the problem is that i need the complexity to be O(logn). the complexity of the code below is said to be O(logn) but from what i understand a recursive method has the growth order of O(n). so the question is what is the growth order of the code below.
Make a moving cursor using doubly linked list in java
I’m trying to write a code for a simple moving cursor in java. I have to use doubly linked list. Also I should implement doubyLinkedList class myself. In this program first we take an integer like n from user as number of lines. Then we take n lines of input. Each line contains only one character which can be <
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 complexity (it needs to be N or lower) I’ve adjusted my code to be able to solve in O(N) but now my correctness has dropped to 77%, I’m
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 = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 steps to the right: [7,1,2,3,4,5,6] rotate 2 steps to the right: [6,7,1,2,3,4,5] rotate 3 steps
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 So this program will check if a given array, contains a certain subarray. My question is, what would the time complexity be for this program? I have tried to calculate it by checking all statements, since variable i can get reset I can not for the world
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 following: caching a new array with a new batch of freshly allocated memory. copying all the elements of the internal array into the new array. setting the internal array
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 …