Editorial for Door(Dasher)
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
This is a problem based on the 2 Pointer and Sliding Window Lesson.
Using the Two-Pointer technique, say with pointers and , maintain the sum of the range . House marks the furthest house one could deliver presents to starting from house , where the sum of the range does not exceed . For every , increase from the previous iteration; as no house has negative children, pointer can only increase.
Both pointers and will start at and increase until (as both pointers never decrease), giving us a time complexity of .
Comments