Double Sequence Pairing¶
Table of Contents¶
- 2037. Minimum Number of Moves to Seat Everyone (Easy)
- 455. Assign Cookies (Easy)
- 2410. Maximum Matching of Players With Trainers (Medium)
- 1433. Check If a String Can Break Another String (Medium)
- 870. Advantage Shuffle (Medium)
- 826. Most Profit Assigning Work (Medium)
- 2449. Minimum Number of Operations to Make Arrays Similar (Hard)
- 1889. Minimum Space Wasted From Packaging (Hard)
- 2561. Rearranging Fruits (Hard)
- 2323. Find Minimum Time to Finish All Jobs II (Medium) 👑
2037. Minimum Number of Moves to Seat Everyone¶
-
LeetCode | LeetCode CH (Easy)
-
Tags: array, greedy, sorting, counting sort
- Return the minimum number of moves needed to seat everyone.
2037. Minimum Number of Moves to Seat Everyone - Python Solution
from typing import List
# Greedy
def minMovesToSeat(seats: List[int], students: List[int]) -> int:
seats.sort()
students.sort()
moves = 0
for i, j in zip(seats, students):
moves += abs(i - j)
return moves
print(minMovesToSeat([3, 1, 5], [2, 7, 4])) # 4
455. Assign Cookies¶
-
LeetCode | LeetCode CH (Easy)
-
Tags: array, two pointers, greedy, sorting
- Return the maximum number of your content children that can be satisfied.
455. Assign Cookies - Python Solution
from typing import List
# Greedy
def findContentChildren(g: List[int], s: List[int]) -> int:
g.sort()
s.sort()
i, j = 0, 0
while i < len(g) and j < len(s):
if g[i] <= s[j]:
i += 1
j += 1
return i
# |-------------|-------------|--------------|
# | Approach | Time | Space |
# |-------------|-------------|--------------|
# | Greedy | O(N * logN) | O(1) |
# |-------------|-------------|--------------|
g = [1, 2, 3]
s = [1, 1]
print(findContentChildren(g, s)) # 1
2410. Maximum Matching of Players With Trainers¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, two pointers, greedy, sorting
1433. Check If a String Can Break Another String¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: string, greedy, sorting
870. Advantage Shuffle¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, two pointers, greedy, sorting
826. Most Profit Assigning Work¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, two pointers, binary search, greedy, sorting
2449. Minimum Number of Operations to Make Arrays Similar¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: array, greedy, sorting
1889. Minimum Space Wasted From Packaging¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: array, binary search, sorting, prefix sum
2561. Rearranging Fruits¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: array, hash table, greedy
2323. Find Minimum Time to Finish All Jobs II¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, greedy, sorting