Skip to content

Practice Guess Number Higher or Lower II

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#375
LeetCode Problem

Guess Number Higher or Lower II

Problem Statement

A secret number is chosen from 1 through n. A correct guess wins without a charge. Each incorrect guess x costs x dollars, and you are told whether the secret is higher or lower before guessing again. You lose if you cannot afford to continue. Return the smallest starting amount that lets you guarantee a win for every possible secret number.

Source: Guess Number Higher or Lower II on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 10
Output
16

# Example 2

Input
n = 1
Output
0

# Example 3

Input
n = 2
Output
1

Constraints

1 <= n <= 200

Related LeetCode Problems

Practice more problems similar to Guess Number Higher or Lower II.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.