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.
Simple work around to achieve O(n) time and space complexity taking advantage of the fact that the array is already sorted. Beats the other solutions since we do not have to sort the array again or run binary search n times. Same space complexity as we have to make a new array for the solution anyway.
Climbing the Leaderboard
You are viewing a single comment's thread. Return to all comments →
Simple work around to achieve O(n) time and space complexity taking advantage of the fact that the array is already sorted. Beats the other solutions since we do not have to sort the array again or run binary search n times. Same space complexity as we have to make a new array for the solution anyway.