We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Good question. Let n be # of elements in our array. The time complexity is O(n) since we visit each element in the array a maximum of 1 times. (Technically, we do sometimes revisit an element, but since we already marked it as visited, we immediatelly return, so this only adds a constant factor to our runtime)
Java 1D Array (Part 2)
You are viewing a single comment's thread. Return to all comments →
Can I know the overall time complexity for your solution to this problem?
Good question. Let n be # of elements in our array. The time complexity is O(n) since we visit each element in the array a maximum of 1 times. (Technically, we do sometimes revisit an element, but since we already marked it as visited, we immediatelly return, so this only adds a constant factor to our runtime)
HackerRank solutions.