less than 1 minute read

You are given a list of integers nums containing 1s and 0s and an integer k. Given that you can set at most k 0s to 1s, return the length of the longest sublist containing all 1s.

Constraints

  • n ≤ 100,000 where n is the length of nums

https://binarysearch.com/problems/Longest-Sublist-of-1s-After-K-Sets

Examples

Example 1

Input

  • nums = [1, 1, 1, 0, 0, 1, 0]
  • k = 2

Output

  • answer = 6

Explanation

We can set the two middle 0s to 1s and then the list becomes [1, 1, 1, 1, 1, 1, 0].

Solution

Leave a comment