Skip to the editor
JSGroundwork
JSGroundwork handwritten · web dev
←Back to Greedy algorithms

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›Greedy algorithms

Candy

advancedlayer I9 · Greedy algorithms5 tests

Children stand in a line and ratings[i] is child i's rating. Hand out candy so that:

  • Every child gets at least one candy
  • A child rated higher than an immediate neighbour gets more candy than that neighbour
  • Equal ratings impose no constraint at all

Return the minimum total number of candies required.

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