Pulkit3714's blog

By Pulkit3714, history, 13 months ago, In English

Hi,

I wrote the following solution using monotonic stack and dp, but it is failing for 2 test cases. Can someone help me with this?

Code:

Spoiler

My understanding is: For each element, we should go to the largest left or right element, that is in sight (no larger element in between). It would be great if someone could point a minimal breaking testcase.

Thanks!

  • Vote: I like it
  • +1
  • Vote: I do not like it

| Write comment?
»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
5
4 1 2 3 3 

Fails for something similar to this.

Best solution : 4 -> 3 -> 2 -> 1

Your solution : 3 -> 2 -> 1

Hope it helps :)