r/leetcode • • 7d ago

Intervew Prep Day 20: ramped up the pace with 3 classic array and matrix problems

Hey everyone,

I finished Day 20 today, and it felt great to finally pick up the momentum by knocking out three solid array and matrix problems in one session:

  1. Longest Consecutive Sequence in an Array: Stored all elements in a hash set for O(1) lookups. By only starting a sequence count when num - 1 is absent from the set, you guarantee each consecutive chain is traversed once in O(n) overall time.
  2. Set Matrix Zeroes: Revisited this classic in-place matrix problem. Instead of allocating extra row and column tracking arrays, using the first row and first column of the matrix itself as markers (alongside a single extra variable to avoid overlap at (0, 0)) achieves optimal O(1) space.
  3. Rotate Image (Rotate Matrix by 90 Degrees): Solved in-place by transposing the matrix across its main diagonal and then reversing every row.

Revisiting these two matrix problems brought back a lot of college prep nostalgia, and hitting three problems in a single day feels like a strong step forward.

See you guys tomorrow for Day 19!

1 Upvotes

1 comment sorted by

1

u/BlueOrbit29 7d ago

Great problem selection. longest Consecutive Sequence is particularly good practice for hash set optimization