Maximizing the no. of consecutive 1 in binary array.

How to solve this problem.

You already have the solution in the link you gave, right? Then why did you ask?

@akshaym_96

I know that I want alternative approach to sliding window which have same time and space complexity as of sliding window solution.

1 Like

Going just by the title of the question, it is similar to SCHEDULE from March Long Challenge and almost similar to DEVSTR from March 15 Challenge, the editorials for which can be found here and here respectively. The editorial for SCHEDULE uses binary-search, but the problem can also be solved using a priority-queue, which keeps the longest segment always on top. A solution using priority queue can be found here.

Please be more clear while you ask a question. As posted by @varuns_2729 it similar to the problems he mentioned but the main difference being maximization. Your question asks for maximizing while his links say minimizing the maximum consecutive 1’s.Please go through his links you will get some idea. Thank you.