Skip to the editor
JSGroundwork
JSGroundwork handwritten · web dev
←Back to Sliding window

Ready to read

JSJavaScript⑂Git◎Interview prepΣDSA in JSSDSystem Design
More topics15›
</>HTML{ }CSS⚛ReactNNext.jsNeNest.jsTSTypeScriptNoNode.js🐳DockerDBSQL & Databases✓Testing🔒Web Security☁Cloud & DevOps◈GraphQL◆Redis☸Kubernetes
☰‹›
Description
All topics›JavaScript›Sliding window

Max Consecutive Ones III

intermediatelayer B5 · Sliding window5 tests

Given a binary array nums (only 0s and 1s) and an integer k, return the length of the longest contiguous run of 1s you can produce by flipping at most k zeros to ones.

  • You do not have to use all k flips
  • k may be 0, in which case you are just finding the longest existing run of ones
  • An empty array yields 0
  • Target complexity: O(n) with O(1) extra space

Stuck?

All exercisesPlayground
1234567891011121314
loading the editor…

Nothing yet — hit Run and whatever you log shows up here.

Submit to see how you did.

⌘/Ctrl + Enter run⌘/Ctrl + S save⌘/Ctrl + / comment⌘/Ctrl + F find/replace⌘/Ctrl + D select next matchAlt + click multi-cursorTab indent · ⇧Tab outdentEsc leave fullscreen