Grokking Coding Mock Interview
Ask Author
Back to course home

0% completed

Solution: Max Consecutive Ones III
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

Given an array nums containing 1 and 0 digits, return the maximum number of consecutive 1s if you can flip at most any k 0s.

Examples

  • Example 1:

    • Input: nums = [1, 0, 1, 1, 0, 0, 1, 1, 1, 0], k = 2
    • Expected Output: 7
    • Justification: Flipping the two 0s in the middle section [0, 0] results in the longest continuous sequence of 1s: [1, 1, 1, 1, 1, 1, 1].
  • Example 2:

    • Input: nums = [0, 1, 1, 0, 1, 0, 1, 0, 1], k = 1
    • Expected Output: 4

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible