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.
That's an interesting problem! It feels like there should be a clever math trick to solve this efficiently, avoiding brute-force looping. I'd probably start by calculating ab, then finding the two multiples of x that bracket it. Then a simple comparison to see which is closer. It reminds me of some of the fun puzzles I enjoy in games. Speaking of which, sometimes when I need a mental break, I mess around with something completely different like Solar Smash and just destroy planets. Great problem though!
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Closest Number
You are viewing a single comment's thread. Return to all comments →
That's an interesting problem! It feels like there should be a clever math trick to solve this efficiently, avoiding brute-force looping. I'd probably start by calculating ab, then finding the two multiples of x that bracket it. Then a simple comparison to see which is closer. It reminds me of some of the fun puzzles I enjoy in games. Speaking of which, sometimes when I need a mental break, I mess around with something completely different like Solar Smash and just destroy planets. Great problem though!