230. XP to Next Level — Binary Search
Easy · Binary Search
A sorted array of XP thresholds marks each level boundary. Given a player's current XP, use binary search to find which level they are on (1-indexed). Level 1 starts at XP 0.
Examples
Example 1 Input: thresholds=[0,100,300,600,1000], xp=450 Output: 4 Explanation: 450 is between 300 and 600, so level 4
Constraints
- 1 ≤ thresholds.length ≤ 50, xp ≥ 0