← all problems

daysToFillJar 🌶️🌶️

You are filling a jar with coins to reach a goal. On day 1 you add 1 coin, on day 2 you add 2 coins, on day 3 you add 3 coins, and so on: one more each day.

Write a method daysToFillJar that takes the goal (0 or more) and returns the first day on which the jar holds at least goal coins. A goal of 0 takes 0 days.

For example, daysToFillJar(10) is 4 (1 + 2 + 3 + 4 = 10), and daysToFillJar(11) is 5.