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.
Java Solution
Here is my solution in Java that passes all cases in O(n log(n)) time with O(1) additional space.
Here is how it works:
We sort keyboards in descending order. We sort usb in ascending order. Then we iterate over them not checking usbs past where 1 usb plus our current keyboard is already greater than s. Read the comments in my solution for a more in depth explanation.
Electronics Shop
You are viewing a single comment's thread. Return to all comments →
Java Solution Here is my solution in Java that passes all cases in O(n log(n)) time with O(1) additional space.
Here is how it works: We sort keyboards in descending order. We sort usb in ascending order. Then we iterate over them not checking usbs past where 1 usb plus our current keyboard is already greater than s. Read the comments in my solution for a more in depth explanation.
Some times HackeRank redirect doesn't work, so here is the direct link you will have to copy and paste: https://github.com/RyanFehr/HackerRank/blob/master/Algorithms/Implementation/Electronics%20Shop/Solution.java