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.
Since all numbers are unique, you can convert original input array to a set, which is O(n) time complexity. And construct a set with each number adding k, which is also O(n).
Then origional_set&with_k_larger_set is just the answer, which costs O(n). Adding all together, the time complexity is O(n).
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Pairs
You are viewing a single comment's thread. Return to all comments →
I used python.
Since all numbers are unique, you can convert original input array to a set, which is O(n) time complexity. And construct a set with each number adding k, which is also O(n).
Then origional_set&with_k_larger_set is just the answer, which costs O(n). Adding all together, the time complexity is O(n).