shyam81295's blog

By shyam81295, history, 8 years ago, In English

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.

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
8 years ago, # |
  Vote: I like it +2 Vote: I do not like it

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.