dsa · easy

Guess the Hidden Number

A hidden integer pick lies in 1 .. n. Your function receives both n and pick. Compare a candidate x to pick the way a guess(x) helper would: negative when x is too large, positive when x is too small, zero when they match. Return the hidden number.

Arguments

Example

n = 10, pick = 6

A probe at 5 is too small, a probe at 8 is too large, a probe at 6 matches → 6.

n = 1, pick = 11.

Constraints

1 <= n <= 2^31 - 1 1 <= pick <= n Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
10
6

Expected:
6

Example 2

Input:
1
1

Expected:
1

Example 3

Input:
2
1

Expected:
1

Open in the Dojo editor