Back to problems

Longest Subarray of Ones

Algorithm · ByteDance · Medium

You are given a binary array nums and an integer k. Return the greatest possible length of a contiguous segment of nums that can become entirely 1s after changing at most k of its 0 entries into 1s. Using fewer than k flips is allowed, and a contiguous segment means a block of adjacent elements with no gaps. Follow-up: Consider the same operation in two dimensions. For a binary matrix grid and an integer k, what is the maximum area of an axis-aligned rectangular region that…

Checking your access…