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

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

I have implemented sliding window method in this problem, but there's TLE for testcase 9 . This is the link. I know the solution is wrong, but I want to know where I am going wrong, so that I shouldn't repeat same mistake again. It would be nice if someone of you will guide me to resolve this issue. Thanking in advance.

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

»
9 лет назад, # |
  Проголосовать: нравится +2 Проголосовать: не нравится

It's clear that, your solution has a complexity of O(n^2). Which is not enough to pass the test cases. This problem is very easy to solve using two pointer algorithm. I'm not sure if you are familiar with this algorithm or not. May be you have implemented this algorithm in a wrong way. Try 16375131.