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.
Unfortunately, your solution is not clear O(n). In your solution you use TreeMap. Complexity of insertion into a tree map is O(logn) (get is O(logn) too). So algorithm complexity is O(nlogn), because on each number your invokes get from and put into a tree. You can change data structure to array, for instance.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Absolute Permutation
You are viewing a single comment's thread. Return to all comments →
Unfortunately, your solution is not clear O(n). In your solution you use TreeMap. Complexity of insertion into a tree map is O(logn) (get is O(logn) too). So algorithm complexity is O(nlogn), because on each number your invokes get from and put into a tree. You can change data structure to array, for instance.