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.
Brilliant. One comment - N is bound to 10^7 and M (K in this code) - only to 2*10^5 (for a total of 4*10^5 points, if no duplicates) - more than an order of magnitude less, so a hashmap may be used instead of of an array. This should improve space complexity for exchange of somewhat worse constant factors.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Array Manipulation
You are viewing a single comment's thread. Return to all comments →
Brilliant. One comment - N is bound to 10^7 and M (K in this code) - only to 2*10^5 (for a total of 4*10^5 points, if no duplicates) - more than an order of magnitude less, so a hashmap may be used instead of of an array. This should improve space complexity for exchange of somewhat worse constant factors.