Grokking 75: Top Coding Interview Questions
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 a binary array nums containing only 0 and 1 and an integer k, return the maximum number of consecutive 1's in the array if you can flip at most k 0's.

Examples

Example 1:

  • Input: nums = [1, 0, 0, 1, 1, 0, 1, 1], k = 2
  • Expected Output: 6
  • Justification: By flipping 0 at the second and fifth index in the list, we get [1, 0, 1, 1, 1, 1, 1, 1], which has 6 consecutive 1s.

Example 2:

  • Input: nums = [1, 0, 1, 1, 0, 0, 1, 1], k = 1
  • Expected Output: 4
  • Justification: By flipping `0

.....

.....

.....

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