#3449
Maximize the Minimum Game Score
HardArrayBinary SearchGreedyBinary SearchGreedy
Approaches
Brute ForceOptimal
Complexity Comparison
| Brute Force | Optimal Solution★ | |
|---|---|---|
| Time | O(n²) | O(n log(max(points))) |
| Space | O(1) | O(1) |
💡
Intuition
Time O(n log(max(points)))Space O(1)
Use binary search to find the maximum possible minimum score. Fix a score x and check if it's achievable with m moves using a greedy approach.
⚙️
Algorithm
3 steps- 1Step 1: Set low = 0 and high = max(points).
- 2Step 2: Perform binary search: for mid = (low + high) / 2, check if we can achieve mid as the minimum score.
- 3Step 3: Adjust low or high based on whether mid is achievable, until low meets high.
solution.py18 lines
1def canAchieve(points, m, x):
2 moves = 0
3 for p in points:
4 if p < x:
5 moves += x - p
6 if moves > m:
7 return False
8 return True
9
10def maxMinScore(points, m):
11 low, high = 0, max(points)
12 while low < high:
13 mid = (low + high + 1) // 2
14 if canAchieve(points, m, mid):
15 low = mid
16 else:
17 high = mid - 1
18 return lowℹ
Complexity note: The binary search runs in O(log(max(points))) and for each mid, we check the scores in O(n), leading to the overall complexity.
- 1Binary search helps efficiently narrow down possible scores.
- 2Greedy checking ensures we validate achievable scores.
Solutions and explanations are original Tejav content. Problem titles © LeetCode — use the LeetCode button above for the full problem statement.