Binary Search Max Answer¶
Table of Contents¶
- 275. H-Index II (Medium)
- 2226. Maximum Candies Allocated to K Children (Medium)
- 2982. Find Longest Special Substring That Occurs Thrice II (Medium)
- 2576. Find the Maximum Number of Marked Indices (Medium)
- 1898. Maximum Number of Removable Characters (Medium)
- 1802. Maximum Value at a Given Index in a Bounded Array (Medium)
- 1642. Furthest Building You Can Reach (Medium)
- 2861. Maximum Number of Alloys (Medium)
- 3007. Maximum Number That Sum of the Prices Is Less Than or Equal to K (Medium)
- 2141. Maximum Running Time of N Computers (Hard)
- 2258. Escape the Spreading Fire (Hard)
- 2071. Maximum Number of Tasks You Can Assign (Hard)
- 1618. Maximum Font to Fit a Sentence in a Screen (Medium) 👑
- 1891. Cutting Ribbons (Medium) 👑
- 2137. Pour Water Between Buckets to Make Water Levels Equal (Medium) 👑
- 644. Maximum Average Subarray II (Hard) 👑
275. H-Index II¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, binary search
2226. Maximum Candies Allocated to K Children¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, binary search
2982. Find Longest Special Substring That Occurs Thrice II¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: hash table, string, binary search, sliding window, counting
2576. Find the Maximum Number of Marked Indices¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, two pointers, binary search, greedy, sorting
from typing import List
# Fast Slow Pointers
def maxNumOfMarkedIndices(nums: List[int]) -> int:
nums.sort()
n = len(nums)
slow, fast = 0, n // 2
count = 0
while slow < n // 2 and fast < n:
if nums[fast] >= 2 * nums[slow]:
count += 2
slow += 1
fast += 1
return count
nums = [3, 5, 2, 4]
print(maxNumOfMarkedIndices(nums)) # 2
1898. Maximum Number of Removable Characters¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, two pointers, string, binary search
1802. Maximum Value at a Given Index in a Bounded Array¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: binary search, greedy
1642. Furthest Building You Can Reach¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, greedy, heap priority queue
2861. Maximum Number of Alloys¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, binary search
3007. Maximum Number That Sum of the Prices Is Less Than or Equal to K¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: binary search, dynamic programming, bit manipulation
2141. Maximum Running Time of N Computers¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: array, binary search, greedy, sorting
2258. Escape the Spreading Fire¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: array, binary search, breadth first search, matrix
2071. Maximum Number of Tasks You Can Assign¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: array, binary search, greedy, queue, sorting, monotonic queue
1618. Maximum Font to Fit a Sentence in a Screen¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, string, binary search, interactive
1891. Cutting Ribbons¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, binary search
2137. Pour Water Between Buckets to Make Water Levels Equal¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, binary search
644. Maximum Average Subarray II¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: array, binary search, prefix sum