Skip to the editor
JSGroundwork
JSGroundwork handwritten · web dev
←Back to Arrays & strings

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›Arrays & strings

Merge Sorted Array In Place

intermediatelayer B2 · Arrays & strings5 tests

nums1 has m real values followed by n zeroes used as padding. nums2 has n values. Both are sorted ascending. Merge nums2 into nums1 so that nums1 ends up fully sorted.

  • Mutate nums1 directly — the return value is ignored
  • Use O(1) extra space; do not build a new array and copy it back
  • Either input may contribute zero elements

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