Ctrl K

Grow and Copy

Medium
A single card showing the number 1 lies on the table. In one move you may do either of the following: - pick any card and increase its number by 1; - pick any card and put down a copy of it showing the same number. Given an integer target, return the fewest moves after which the numbers on all cards add up to at least target.
Example 1
target=10 → 5

Raise the card twice to 3 and make three copies: 3 + 3 + 3 + 3 = 12 ≥ 10. That is 5 moves, and fewer is not possible.

Example 2
target=4 → 2

For example, raise the card to 2 and copy it once: 2 + 2 = 4, which takes 2 moves.

Example 3
target=1 → 0

The single card already sums to 1, so no moves are needed.

Constraints
  • 1 ≤ target ≤ 10⁵
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsTerms Sharing a Last Digit MediumErase Digits Until It Divides by 25 MediumPrimes Below a Bound MediumSmallest Number From Digit Factors MediumOne Digit Swap Medium
loading Python…
Input
target=10
Expected
5

Run checks the first 3 tests in your browser. Submit checks all 61 tests on the server, hidden ones included.