Sorting with Stacks - HackerEarth

Hello CodeChef Community,

Here is the Question Link from Ittiam Think challenge 2017 on Hackerearth

I attempted this problem but it got partially accepted.I can change my recursive approach to iterative one to avoid TLE but I don’t know why I am getting WA in some of test cases with this solution.

Here is my solution link.

Please point out my mistake :slight_smile:

You set the modulo value as 10e9+7 instead of 1e9+7 :stuck_out_tongue:

1 Like

@meooow Could you please explain how did you solve this problem?
My question thread has no answers yet.

Lol. And he still got correct answer for those many TCs?! :stuck_out_tongue:

Did you take a look at the editorial? If you have difficulty understanding it then I can explain :slight_smile:

yes,I did.I understood how we can reduce it to another problem, but was having difficulty in understanding how 1d dp mask was able to compute everything(dp state wasn’t clear to me).Thanks!

Thanks a lot! @meoow I made this silly mistake and was searching for error in code from long
@vijju123 I think I got ACs since there are many test cases where the result would be less than 1e9+7 :wink:

1 Like

I wrote an answer under your question thread, here.

True that. I remember once during a hackerrank contest, i used 10^7 +9 instead of 10^9 +7. Got 5/30 points on that problem. Lol XD.