I used 2 pointer approach here but im not able to print the array after splitting 0 with 1’s
1 count problem
Hello @sktg99
What you can do is maintain two variables to keep a track of indices (one for the left end and one for the right end) and update these variables when a new length > maxlength is encountered.
The modified code
The two variables that I have used are “maxLengthL” and “maxLengthR”.
its giving wrong answer for one test case
Hello @sktg99
I have modified my code so that
maxLengthL = -1 and maxLengthR = -1 initially because I thought of a testcase on which my code would fail
Testcase is
5 0
0 0 0 0 0
Here is the modified code
https://ide.codingblocks.com/s/161293 Try this and see if it works.