Skip to the editor
JSGroundwork
JSGroundwork handwritten · web dev
←Back to Advanced DP

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›Advanced DP

Minimum Cost to Cut a Stick

advancedlayer A1 · Advanced DP4 tests

A wooden stick of length n lies from position 0 to position n. You are given cuts, the positions you must cut at, in any order you like. Cutting a piece costs the length of that piece, and the cut splits it in two. Return the minimum total cost of performing all the cuts.

  • You may perform the cuts in any order, and the order changes the cost
  • cuts is not sorted
  • No cuts at all costs 0
  • Example: n = 7 with cuts = [1, 3, 4, 5] costs 16

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