DEV Community

Cover image for Rocks D. Xebec
Brian Kim
Brian Kim

Posted on

Rocks D. Xebec

🪨 The Big Rocks of DSA

Core Concepts + Analogies + Common Problems + Time & Space Complexity

Most DSA problems are just one of these big rocks in disguise.

Identify the rock → solution shape → complexity answer.


🪨 BIG ROCK #1: COUNTING & MEMORY

(Hash Maps, Arrays)

🧠 Core Concept

Remember what you’ve seen so you don’t redo work.

🎓 Analogy

Taking attendance once instead of recounting the room.

Common Problems + Complexity

Problem Time Space
Two Sum O(n) O(n)
Majority Element O(n) O(n)
Group Anagrams O(n·k) O(n)
First Unique Character O(n) O(1) / O(n)

🧠 Counting = Hash Map


🪨 BIG ROCK #2: SHRINKING THE SEARCH SPACE

(Two Pointers)

🧠 Core Concept

Solve faster by closing in from both ends.

🧹 Analogy

Cleaning a table from left and right.

Common Problems + Complexity

Problem Time Space
Valid Palindrome O(n) O(1)
Container With Most Water O(n) O(1)
Remove Duplicates (sorted) O(n) O(1)

🧠 Sorted data = Two Pointers


🪨 BIG ROCK #3: CONTINUOUS RANGE CONTROL

(Sliding Window)

🧠 Core Concept

Track a moving range without restarting.

🚗 Analogy

Driving forward while looking through a window.

Common Problems + Complexity

Problem Time Space
Longest Substring Without Repeating Characters O(n) O(n)
Max Sum Subarray O(n) O(1)
Minimum Window Substring O(n) O(n)

🧠 Continuous range = Sliding Window


🪨 BIG ROCK #4: LAST ACTION MATTERS MOST

(Stack)

🧠 Core Concept

Most recent action controls the next step.

🍽️ Analogy

Plates stacked in a sink.

Common Problems + Complexity

Problem Time Space
Valid Parentheses O(n) O(n)
Daily Temperatures O(n) O(n)
Min Stack O(1) O(n)

🧠 Nested / undo = Stack


🪨 BIG ROCK #5: FOLLOW THE NEXT POINTER

(Linked Lists)

🧠 Core Concept

You only know where to go next.

🧭 Analogy

Scavenger hunt clues.

Common Problems + Complexity

Problem Time Space
Reverse Linked List O(n) O(1)
Merge Two Lists O(n) O(1)
Detect Cycle O(n) O(1)
Remove Nth Node O(n) O(1)

🧠 No random access = Linked List


🪨 BIG ROCK #6: BRANCHING DECISIONS

(Trees)

🧠 Core Concept

Each choice creates new paths.

🌳 Analogy

Family tree.

Common Problems + Complexity

Problem Time Space
Max Depth of Binary Tree O(n) O(h)
Invert Binary Tree O(n) O(h)
Validate BST O(n) O(h)
Lowest Common Ancestor O(n) O(h)

h = tree height

🧠 Hierarchy = Tree


🪨 BIG ROCK #7: SOLVE SMALL TO SOLVE BIG

(Recursion)

🧠 Core Concept

Same problem, smaller input.

🪆 Analogy

Russian nesting dolls.

Common Problems + Complexity

Problem Time Space
Fibonacci (naive) O(2ⁿ) O(n)
Fibonacci (memoized) O(n) O(n)
Merge Sort O(n log n) O(n)

🧠 Self-similar = Recursion


🪨 BIG ROCK #8: TRY, FAIL, UNDO

(Backtracking)

🧠 Core Concept

Explore all possibilities safely.

👕 Analogy

Trying outfits before leaving.

Common Problems + Complexity

Problem Time Space
Subsets O(2ⁿ) O(n)
Permutations O(n!) O(n)
Combination Sum Exponential O(n)
Word Search O(m·n·4ᵏ) O(k)

🧠 All possibilities = Backtracking


🪨 BIG ROCK #9: ALWAYS PICK THE BEST NEXT

(Heaps)

🧠 Core Concept

Priority beats order.

🚑 Analogy

Emergency room triage.

Common Problems + Complexity

Problem Time Space
Kth Largest Element O(n log k) O(k)
Top K Frequent O(n log k) O(n)
Merge K Sorted Lists O(n log k) O(k)

🧠 Top / best / worst = Heap


🪨 BIG ROCK #10: CONNECTED WORLDS

(Graphs)

🧠 Core Concept

Relationships matter more than order.

🗺️ Analogy

City map.

Common Problems + Complexity

Problem Time Space
Number of Islands O(m·n) O(m·n)
Course Schedule O(V + E) O(V + E)
Clone Graph O(V + E) O(V)

🧠 Free connections = Graph


🪨 BIG ROCK #11: DON’T REPEAT WORK

(Dynamic Programming)

🧠 Core Concept

Store results to avoid recomputation.

🏋️ Analogy

Progressive overload tracking.

Common Problems + Complexity

Problem Time Space
Climbing Stairs O(n) O(1)
House Robber O(n) O(1)
Coin Change O(n·m) O(n)
LIS O(n²) / O(n log n) O(n)

🧠 Optimization = DP


🪨 BIG ROCK #12: BINARY STATES

(Bit Manipulation)

🧠 Core Concept

On / off decisions only.

💡 Analogy

Light switches.

Common Problems + Complexity

Problem Time Space
Single Number O(n) O(1)
Counting Bits O(n) O(n)
Missing Number O(n) O(1)

🧠 Toggle logic = Bits


🧭 Interview Cheat Code

  1. Identify the Big Rock
  2. State the pattern
  3. Explain why it’s optimal
  4. Drop time & space complexity confidently

That alone puts you ahead of most candidates.

Top comments (0)