Week 01 - Arrays, Strings & Hash Maps

Reference extracted from the detailed guide.

Day 1-2: Arrays & Two Pointers

Watch First (Essential):

Problems in Order:

#LeetCodeProblem NameDifficultyPatternVideo Solution
1LC #1Two SumEasyHash Maphttps://www.youtube.com/watch?v=KLlXCFG5TnA
2LC #121Best Time to Buy and Sell StockEasySliding Windowhttps://www.youtube.com/watch?v=1pkOgXD63yU
3LC #217Contains DuplicateEasyHash Sethttps://www.youtube.com/watch?v=3OamzN90kPg
4LC #238Product of Array Except SelfMediumPrefix/Suffixhttps://www.youtube.com/watch?v=bNvIQI2wAjk
5LC #53Maximum SubarrayMediumKadane'shttps://www.youtube.com/watch?v=5WZl3MMT0Eg
6LC #152Maximum Product SubarrayMediumDP/Kadane'shttps://www.youtube.com/watch?v=lXVy6YWFcRM
7LC #153Find Minimum in Rotated Sorted ArrayMediumBinary Searchhttps://www.youtube.com/watch?v=nIVW4P8b1VA
8LC #33Search in Rotated Sorted ArrayMediumBinary Searchhttps://www.youtube.com/watch?v=U8XENwh8Oy8
9LC #11Container With Most WaterMediumTwo Pointershttps://www.youtube.com/watch?v=UuiTKBwPgAo
10LC #153SumMediumTwo Pointershttps://www.youtube.com/watch?v=jzZsG8n2R9A

How to solve each:

LC #1 (Two Sum):
1. Brute force: O(n²) - two nested loops
2. Optimal: O(n) - use hash map to store {value: index}
3. One pass: check if (target - num) exists in map

LC #121 (Best Time to Buy/Sell):
1. Track minimum price seen so far
2. At each price, calculate profit = current - min
3. Track maximum profit

LC #11 (Container With Most Water):
1. Two pointers at start and end
2. Calculate area = min(height[l], height[r]) * (r - l)
3. Move the pointer with smaller height inward

Day 3-4: Hash Maps Deep Dive

Watch First:

Problems in Order:

#LeetCodeProblem NameDifficultyPatternVideo Solution
1LC #242Valid AnagramEasyHash Map Counthttps://www.youtube.com/watch?v=9UtInBqnCgA
2LC #49Group AnagramsMediumHash Map + Sorthttps://www.youtube.com/watch?v=vzdNOK2oB2E
3LC #347Top K Frequent ElementsMediumHash Map + Heaphttps://www.youtube.com/watch?v=YPTqKIgVk-k
4LC #271Encode and Decode StringsMediumDelimiterhttps://www.youtube.com/watch?v=B1k_sxOSgv8
5LC #128Longest Consecutive SequenceMediumHash Sethttps://www.youtube.com/watch?v=P6RZZMu_maU
6LC #146LRU CacheMediumHash Map + DLLhttps://www.youtube.com/watch?v=7ABFKPK2hD4
7LC #380Insert Delete GetRandom O(1)MediumHash Map + Arrayhttps://www.youtube.com/watch?v=j4KwhBziOpg
8LC #560Subarray Sum Equals KMediumPrefix Sum + Maphttps://www.youtube.com/watch?v=fFVZt-6sgyo

Key Templates:

# Template: Frequency Count
from collections import Counter
freq = Counter(nums)  # or Counter(s) for strings

# Template: Two Sum Pattern (find pair)
seen = {}
for i, num in enumerate(nums):
    complement = target - num
    if complement in seen:
        return [seen[complement], i]
    seen[num] = i

# Template: Group by Key
from collections import defaultdict
groups = defaultdict(list)
for item in items:
    key = get_key(item)  # e.g., tuple(sorted(item))
    groups[key].append(item)

Day 5-7: Linked Lists

Watch First:

Problems in Order:

#LeetCodeProblem NameDifficultyPatternVideo Solution
1LC #206Reverse Linked ListEasyIterative/Recursivehttps://www.youtube.com/watch?v=G0_I-ZF0S38
2LC #21Merge Two Sorted ListsEasyTwo Pointershttps://www.youtube.com/watch?v=XIdigk956u0
3LC #141Linked List CycleEasyFast/Slow Pointerhttps://www.youtube.com/watch?v=gBTe7lFR3vc
4LC #142Linked List Cycle IIMediumFloyd's Algorithmhttps://www.youtube.com/watch?v=wjYnzkAhcNk
5LC #143Reorder ListMediumMultiple Techniqueshttps://www.youtube.com/watch?v=S5bfdUTrKLM
6LC #19Remove Nth Node From EndMediumTwo Pointershttps://www.youtube.com/watch?v=XVuQxVej6y8
7LC #23Merge K Sorted ListsHardHeap/Divide Conquerhttps://www.youtube.com/watch?v=q5a5OiGbT6Q

Key Templates:

# Template: Reverse Linked List
def reverse(head):
    prev, curr = None, head
    while curr:
        nxt = curr.next
        curr.next = prev
        prev = curr
        curr = nxt
    return prev

# Template: Fast/Slow Pointer (find middle)
def find_middle(head):
    slow = fast = head
    while fast and fast.next:
        slow = slow.next
        fast = fast.next.next
    return slow

# Template: Dummy Node (for edge cases)
dummy = ListNode(0)
dummy.next = head
# ... operations
return dummy.next

Comments

Share your approach or ask questions

0 comments
?
|
Markdown supported
Sign in to post

Loading comments...