Back to problems

Implement Sliding Windows and LRU Cache

Object-Oriented Programming · ByteDance · Medium

Task 1: Longest Subarray of Ones Approach 1: Try Every Possible Deletion The most direct way to interpret the problem is to actually remove each element, one at a time, and measure the longest continuous block of 1s that remains. For every index we skip, we run a linear scan over the rest of the array while maintaining the current run of consecutive 1s and the best run found so far. For example, take nums = [1, 0, 1, 1]. If we remove index 1, the remaining values are [1, 1,…

Checking your access…