Блог пользователя OverKiller

Автор OverKiller, история, 6 лет назад, По-английски

This problem appeared in a Hiring Challenge on Hackerrank and i couldn't solve it in better than $$$O(N^2)$$$ which was giving TLE. Here is the problem below:

Спойлер

I can't think of a solution better than $$$O(N^2)$$$. Any help/hints will be appreciated.

  • Проголосовать: нравится
  • -19
  • Проголосовать: не нравится

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

Consider, that you will never be able to make a jump larger than $$$O(\sqrt{n})$$$. Using that, you can solve in $$$O(n\sqrt{n})$$$

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Also can anyone tell me why am i getting downvotes? i am just curious to know.