Created
December 7, 2022 10:54
-
-
Save Shaddyjr/6ab463d2330af01f8feca28cec33bb54 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // source: https://www.hackerrank.com/challenges/chocolate-feast/problem | |
| // video: https://youtu.be/TPjNYmUzOdg | |
| function chocolateFeast(n, c, m) { | |
| // initial buy | |
| let bars = Math.floor(n/c) | |
| let wrappers = bars | |
| while (wrappers >= m){ | |
| // buy more bars | |
| const additionalBars = Math.floor(wrappers/m) | |
| bars += additionalBars | |
| // handle reduction of old & addition of new wrappers | |
| wrappers = wrappers % m | |
| wrappers += additionalBars | |
| } | |
| return bars | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment