Problem:
Caring for a plant can be hard work, but since you tend to it regularly, you have a plant that grows consistently. Each day, its height increases by a fixed amount represented by the integer upSpeed. But due to lack of sunlight, the plant decreases in height every night, by an amount represented by downSpeed.
Since you grew the plant from a seed, it started at height 0 initially. Given an integer desiredHeight, your task is to find how many days it'll take for the plant to reach this height.
Example
For upSpeed = 100, downSpeed = 10, and desiredHeight = 910, the output should be
growingPlant(upSpeed, downSpeed, desiredHeight) = 10.
The plant first reaches a height of 910 on day 10.
-Summary-
1. set current_height and count_day as a zero.
2. keep looping until current_height becomes greater than or equal to desiredHeight.
(Always add upSpeed first and subtract downSpeed after check if current height is greater or greater than or equal to desiredHeight)
3. return count
모든 문제에 대한 저작권은 CodeSignal 회사에 있습니다. [Copyright © 2020 BrainFights Inc. All rights reserved]
'CodeSignal > Arcade' 카테고리의 다른 글
CodeSignal [40/60] longestDigitsPrefix (0) | 2020.05.26 |
---|---|
CodeSignal [39/60] knapsackLight (0) | 2020.05.26 |
CodeSignal [37/60] arrayMaxConsecutiveSum (0) | 2020.05.25 |
CodeSignal [36/60] differentSymbolsNaive (0) | 2020.05.25 |
CodeSignal [35/60] firstDigit (0) | 2020.05.25 |
댓글