Перейти к содержимому

Max Number of K-Sum Pairs (LeetCode 1679) | Two Pointers Explained

Dry Run

0:00 / 0:00

Max Number of K-Sum Pairs (LeetCode 1679) | Two Pointers Explained

1 просмотр · 2 нед. назад
Dry Run
1 просмотр · 2 нед. назад
Count the maximum number of k-sum pairs with two pointers (LeetCode 1679), explained visually and traced line by line. Sort the numbers, then walk inward: too small, move the left pointer; too big, move the right pointer; on a match, count the pair and move both. O(n log n) time because of the sort, in Python. Episode 6 of Season 1 on Dry Run, Part 2, pair sums. Season 1 is one pattern, two pointers, across 22 interview problems in 7 parts. Every episode goes intuition, brute force, key insight, code, then a full dry run. 0:00 Start 0:40 Recap 1:02 The problem 1:41 Brute force 2:28 Key insight 3:04 The code 3:36 Dry run 4:32 Common mistakes 5:07 Complexity 5:31 Interview follow-ups 6:11 The pattern Pattern: two pointers on sorted data, count every match Time: O(n log n) · Extra memory: L, R and the count, besides the sort Previous: 167 Two Sum II Next: 881 Boats to Save People #TwoPointers #LeetCode #DSA