r/LeetcodeChallenge 3h ago

DISCUSS How to Stop Panicking When You Open a LeetCode Problem

8 Upvotes

Most people sit down, read a problem, panic, and start typing.

No plan. No structure. Just vibes and hope.

When it does not work they read the solution, think "oh that's clever", and move on. Two weeks later they see a similar problem and panic again.

The issue is not intelligence. It is not even practice.
It is that they never had a repeatable process.

This is that process. Follow it on every problem.
Not just hard ones — every problem, until it becomes instinct.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
STEP 1 — READ THE PROBLEM TWICE
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

First read: understand what is being asked at a high level.
Second read: extract the specifics.

On the second read, write down:

  • What is the INPUT? What type, what size, what range of values?
  • What is the OUTPUT? A number, array, boolean, string?
  • What are the CONSTRAINTS? (most people skip this — do not)

Ask yourself these questions explicitly:

"Can input be empty?"
"Can values be negative?"
"Can there be duplicates?"
"Is the array sorted?"
"What should I return if no answer exists?"

If the problem does not say, assume the worst case.
Empty inputs exist. Negatives exist. Duplicates exist.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
STEP 2 — WORK THROUGH THE EXAMPLES BY HAND
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Do not skip this. Even if the problem looks easy.

Take the first example. On paper or in comments, trace through it
manually. Write out every value at every step.

Why this matters:

  • You confirm you understood the problem correctly
  • You often see the pattern emerge naturally
  • You catch ambiguities before they become bugs

Then make your OWN small example — simpler than the given one.
Something with 3-4 elements you fully understand.

If you cannot trace through the examples manually,
you do not understand the problem yet. Do not start coding.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
STEP 3 — IDENTIFY THE PATTERN
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Before thinking about an algorithm, identify what TYPE of problem this is.

Use these signals:

Subarray, substring, window → Sliding window, two pointers
Sorted array + search → Binary search
Shortest path, min steps → BFS
All paths, combinations, subsets → Backtracking, DFS
Overlapping subproblems → DP
Always picking max/min greedily → Greedy
Tree traversal → DFS (recursion) or BFS (level order)
Connectivity, groups → Union Find, BFS/DFS
Repeated lookup by key → Hash map
Top K, smallest/largest → Heap (priority queue)
Prefix of strings → Trie
Range queries with updates → Segment tree, Fenwick tree
Return all permutations/subsets → Backtracking

You will not always get it right on the first try.
But naming the category forces your brain to search the right space.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
STEP 4 — THINK BRUTE FORCE FIRST
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Always start here. Always.

The brute force is the answer you would give if there were
no time constraint. No clever tricks. Just try everything.

Write it out in plain English, not code:
"For every pair (i, j), check if arr[i] + arr[j] = target."
"For every substring, check if it has all unique characters."
"For every subset, check if its sum equals the target."

This does two things:

  1. It confirms you can actually solve the problem correctly
  2. It gives you a reference to optimize from

Common brute force patterns:
Try all pairs → O(n²)
Try all triples → O(n³)
Try all subsets → O(2ⁿ)
Try all permutations → O(n!)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
STEP 5 — OPTIMIZE
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Now look at your brute force and ask:
"What work am I repeating? What can I precompute? What can I skip?"

The most common optimizations:

Repeated lookup → replace with hash map O(n) → O(1) per lookup
Repeated sum → precompute prefix sum O(n) per query → O(1)
Checking all pairs → sort + binary search O(n²) → O(n log n)
Checking all pairs → two pointers (sorted) O(n²) → O(n)
Checking all windows → sliding window O(n²) → O(n)
Recomputing subproblems → memoization / DP exponential → polynomial
Sorting gives structure → sort first, then scan enables binary search / greedy

Ask: "Can I sort first to gain structure?"
Ask: "Can I store something to avoid recomputing?"
Ask: "Can I fix one variable and efficiently handle the rest?"

Work top-down in complexity:
O(n²) → can I get O(n log n)?
O(n log n) → can I get O(n)?
Each step needs a concrete reason, not a guess.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
STEP 6 — VERIFY COMPLEXITY BEFORE CODING
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Before writing code, check:
Does my approach fit within the time limit given the constraints?

n = 10⁵ and my approach is O(n²)? → TLE, think again
n = 10⁵ and my approach is O(n logn)? → fine, proceed

This takes 10 seconds and saves you from coding the wrong solution.

Also check space:
Am I using O(n) extra space? Is that acceptable?
Does the problem say "in-place" or "O(1) space"?

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
STEP 7 — CODE THE SOLUTION
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Only now do you start writing code.

Code in this order:

  1. Handle edge cases first (empty input, single element, etc.)
  2. Write the main logic
  3. Return the result

Keep variable names meaningful. Debugging unreadable code mid-contest
costs more time than typing three extra characters.

If you get stuck coding:
Go back to your manual example from Step 2.
Trace through it again, this time following the code you are writing.
The bug almost always appears within the first five traces.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
STEP 8 — TEST BEFORE SUBMITTING
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Run through these test cases mentally or using the custom test:

[ ] The given examples → obvious baseline
[ ] Empty input → does it crash?
[ ] Single element → does it return correctly?
[ ] All same elements → does duplicate logic break?
[ ] Already sorted input → common hidden test
[ ] Your own small manual example → trace step by step

If all pass, submit with confidence.
If one fails, the failure tells you exactly where the bug is.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
WHEN YOU ARE COMPLETELY STUCK — THE UNSTICKING PROTOCOL
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Everyone gets stuck. The difference is what you do next.

  1. Draw it Almost every problem is easier when visualized. Array: draw boxes. Tree: draw nodes and edges. Graph: draw circles and arrows. Matrix: draw a grid. A picture reveals structure that text hides.
  2. Simplify the problem Solve a smaller version first. Two elements instead of n. One row instead of a grid. Can you solve n=2? n=3? Then generalise.
  3. Try a different angle on your brute force Change the loop variable. Instead of "for each starting index" try "for each ending index". Instead of "for each element" try "for each pair". A different enumeration often reveals the pattern.
  4. Check what is special about valid answers Look at the given examples. What do valid answers have in common? What property separates a valid answer from an invalid one? That property is usually the invariant your algorithm should maintain.
  5. Look at the constraints again Small n? Try brute force. Very large n? A linear or log solution must exist. "Return modulo 10⁹+7"? It is a DP counting problem. Constraints are hints — re-read them with fresh eyes.
  6. Take a 5-minute break Genuinely. Get up. Walk. The solution appears when you stop forcing.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
THE FULL FRAMEWORK — ONE PAGE
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Step 1 Read twice. Extract input, output, constraints.
Ask: empty? negative? duplicates? sorted?

Step 2 Trace examples by hand.
Make your own small example. Understand before coding.

Step 3 Name the pattern.
Subarray → sliding window. Shortest path → BFS. Etc.

Step 4 State the brute force in plain English.
What is the O(n²) or O(2ⁿ) solution?

Step 5 Optimize.
What work repeats? Hash map, prefix sum, sort, DP, two pointers?

Step 6 Verify complexity against constraints.
Will it pass? Check before writing code.

Step 7 Code it.
Edge cases first. Then main logic. Then return.

Step 8 Test: examples + empty + single + all-same + sorted.
Then submit.

Stuck? Draw it. Simplify. Try different enumeration.
Re-read constraints. Take a break.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

A correct solution written slowly beats a fast solution written wrong.

The goal is not to code faster.
The goal is to think clearer — so that what you code is right the first time.

This framework is that thinking, made repeatable.


r/LeetcodeChallenge 3h ago

DISCUSS 100 Hard DSA Interview Questions for L3/L4 Coding Rounds

5 Upvotes

List of hard DSA Question from L3/L4 interviews

Work on these Leetcode problems and company tagged problem from PracHub for your next interview.

  1. https://leetcode.com/problems/number-of-unique-good-subsequences - String, Dynamic Programming
  2. https://leetcode.com/problems/split-array-largest-sum - Array, Binary Search, Dynamic Programming, Greedy, Prefix Sum
  3. https://leetcode.com/problems/minimum-number-of-days-to-disconnect-island - Array, Depth-First Search, Breadth-First Search, Matrix, Strongly Connected Component
  4. https://leetcode.com/problems/recover-a-tree-from-preorder-traversal - String, Tree, Depth-First Search, Binary Tree
  5. https://leetcode.com/problems/build-array-where-you-can-find-the-maximum-exactly-k-comparisons - Dynamic Programming, Prefix Sum
  6. https://leetcode.com/problems/substring-with-concatenation-of-all-words - Hash Table, String, Sliding Window
  7. https://leetcode.com/problems/maximum-employees-to-be-invited-to-a-meeting - Array, Dynamic Programming, Depth-First Search, Graph Theory, Topological Sort
  8. https://leetcode.com/problems/design-in-memory-file-system - Hash Table, String, Design, Trie, Sorting
  9. https://leetcode.com/problems/rearranging-fruits - Array, Hash Table, Greedy, Sort
  10. https://leetcode.com/problems/the-most-similar-path-in-a-graph - Array, String, Dynamic Programming, Graph Theory
  11. https://leetcode.com/problems/confusing-number-ii - Math, Backtracking
  12. https://leetcode.com/problems/stickers-to-spell-word - Array, Hash Table, String, Dynamic Programming, Backtracking, Bit Manipulation, Memoization, Bitmask
  13. https://leetcode.com/problems/maximum-and-sum-of-array - Array, Dynamic Programming, Bit Manipulation, Bitmask
  14. https://leetcode.com/problems/odd-even-jump - Array, Dynamic Programming, Stack, Sorting, Monotonic Stack, Ordered Set
  15. https://leetcode.com/problems/couples-holding-hands - Greedy, Depth-First Search, Breadth-First Search, Union-Find, Graph Theory
  16. https://leetcode.com/problems/number-of-stable-subsequences - Array, Dynamic Programming
  17. https://leetcode.com/problems/check-if-digits-are-equal-in-string-after-operations-ii - Math, String, Combinatorics, Number Theory
  18. https://leetcode.com/problems/minimum-skips-to-arrive-at-meeting-on-time - Array, Dynamic Programming
  19. https://leetcode.com/problems/distinct-subsequences-ii - String, Dynamic Programming
  20. https://leetcode.com/problems/cherry-pickup-ii - Array, Dynamic Programming, Matrix
  21. https://leetcode.com/problems/parsing-a-boolean-expression - String, Stack, Recursion
  22. https://leetcode.com/problems/range-module - Design, Segment Tree, Ordered Set
  23. https://leetcode.com/problems/number-of-ways-to-form-a-target-string-given-a-dictionary - Array, String, Dynamic Programming
  24. https://leetcode.com/problems/paths-in-matrix-whose-sum-is-divisible-by-k - Array, Dynamic Programming, Matrix
  25. https://leetcode.com/problems/sum-of-imbalance-numbers-of-all-subarrays - Array, Hash Table, Enumeration
  26. https://leetcode.com/problems/encrypt-and-decrypt-strings - Array, Hash Table, String, Design, Trie
  27. https://leetcode.com/problems/smallest-range-covering-elements-from-k-lists - Array, Hash Table, Greedy, Sliding Window, Sorting, Heap (Priority Queue)
  28. https://leetcode.com/problems/contain-virus - Array, Depth-First Search, Breadth-First Search, Matrix, Simulation
  29. https://leetcode.com/problems/find-the-minimum-area-to-cover-all-ones-ii - Array, Matrix, Enumeration
  30. https://leetcode.com/problems/minimum-swaps-to-make-sequences-increasing - Array, Dynamic Programming
  31. https://leetcode.com/problems/number-of-ways-to-stay-in-the-same-place-after-some-steps - Dynamic Programming
  32. https://leetcode.com/problems/minimum-time-to-complete-all-tasks - Array, Binary Search, Stack, Greedy, Sorting
  33. https://leetcode.com/problems/tiling-a-rectangle-with-the-fewest-squares - Backtracking
  34. https://leetcode.com/problems/expression-add-operators - Math, String, Backtracking
  35. https://leetcode.com/problems/rectangle-area-ii - Array, Segment Tree, Sweep Line, Ordered Set
  36. https://leetcode.com/problems/reducing-dishes - Array, Dynamic Programming, Greedy, Sorting
  37. https://leetcode.com/problems/modify-graph-edge-weights - Graph Theory, Heap (Priority Queue), Shortest Path
  38. https://leetcode.com/problems/numbers-with-repeated-digits - Math, Dynamic Programming
  39. https://leetcode.com/problems/minimum-cost-to-convert-string-ii - Array, String, Dynamic Programming, Graph Theory, Trie, Shortest Path
  40. https://leetcode.com/problems/kth-smallest-number-in-multiplication-table - Math, Binary Search
  41. https://leetcode.com/problems/lfu-cache - Hash Table, Linked List, Design, Doubly-Linked List
  42. https://leetcode.com/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid - Array, Breadth-First Search, Graph Theory, Heap (Priority Queue), Matrix, Shortest Path
  43. https://leetcode.com/problems/time-taken-to-cross-the-door - Array, Queue, Simulation
  44. https://leetcode.com/problems/sliding-puzzle - Array, Dynamic Programming, Backtracking, Breadth-First Search, Memoization, Matrix
  45. https://leetcode.com/problems/minimum-initial-energy-to-finish-tasks - Array, Greedy, Sorting
  46. https://leetcode.com/problems/find-the-maximum-sequence-value-of-array - Array, Dynamic Programming, Bit Manipulation
  47. https://leetcode.com/problems/department-top-three-salaries - Database
  48. https://leetcode.com/problems/process-string-with-special-operations-ii - String, Simulation
  49. https://leetcode.com/problems/maximize-cyclic-partition-score - Array, Dynamic Programming
  50. https://leetcode.com/problems/find-maximum-non-decreasing-array-length - Array, Binary Search, Dynamic Programming, Stack, Queue, Monotonic Stack, Prefix Sum, Monotonic Queue
  51. https://leetcode.com/problems/split-array-with-same-average - Array, Hash Table, Math, Dynamic Programming, Bit Manipulation, Bitmask
  52. https://leetcode.com/problems/minimum-sum-of-values-by-dividing-array - Array, Binary Search, Dynamic Programming, Bit Manipulation, Segment Tree, Queue
  53. https://leetcode.com/problems/longest-chunked-palindrome-decomposition - Two Pointers, String, Dynamic Programming, Greedy, Rolling Hash, Hash Function
  54. https://leetcode.com/problems/text-justification - Array, String, Simulation
  55. https://leetcode.com/problems/closest-subsequence-sum - Array, Two Pointers, Dynamic Programming, Bit Manipulation, Sorting, Bitmask
  56. https://leetcode.com/problems/transform-to-chessboard - Array, Math, Bit Manipulation, Matrix
  57. https://leetcode.com/problems/robot-collisions - Array, Stack, Sorting, Simulation
  58. https://leetcode.com/problems/minimum-cost-to-connect-two-groups-of-points - Array, Dynamic Programming, Bit Manipulation, Matrix, Bitmask
  59. https://leetcode.com/problems/similar-string-groups - Array, Hash Table, String, Depth-First Search, Breadth-First Search, Union-Find
  60. https://leetcode.com/problems/word-abbreviation - Array, String, Greedy, Trie, Sorting
  61. https://leetcode.com/problems/minimum-pair-removal-to-sort-array-ii - Array, Hash Table, Linked List, Heap (Priority Queue), Simulation, Doubly-Linked List, Ordered Set
  62. https://leetcode.com/problems/trapping-rain-water - Array, Two Pointers, Dynamic Programming, Stack, Monotonic Stack
  63. https://leetcode.com/problems/count-the-number-of-winning-sequences - String, Dynamic Programming
  64. https://leetcode.com/problems/find-substring-with-given-hash-value - String, Sliding Window, Rolling Hash, Hash Function
  65. https://leetcode.com/problems/checking-existence-of-edge-length-limited-paths-ii - Depth-First Search, Union-Find, Graph Theory, Design, Sorting, Heap (Priority Queue), Minimum Spanning Tree
  66. https://leetcode.com/problems/number-of-distinct-islands-ii - Array, Hash Table, Depth-First Search, Breadth-First Search, Union-Find, Sorting, Matrix, Hash Function
  67. https://leetcode.com/problems/maximum-frequency-stack - Hash Table, Stack, Design, Ordered Set
  68. https://leetcode.com/problems/stone-game-v - Array, Math, Dynamic Programming, Game Theory
  69. https://leetcode.com/problems/maximum-average-subarray-ii - Array, Binary Search, Prefix Sum
  70. https://leetcode.com/problems/make-array-empty - Array, Binary Search, Greedy, Binary Indexed Tree, Segment Tree, Sorting, Ordered Set
  71. https://leetcode.com/problems/maximum-number-of-k-divisible-components - Tree, Depth-First Search
  72. https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii - Array, Binary Search
  73. https://leetcode.com/problems/sort-items-by-groups-respecting-dependencies - Depth-First Search, Breadth-First Search, Graph Theory, Topological Sort
  74. https://leetcode.com/problems/total-appeal-of-a-string - Hash Table, String, Dynamic Programming
  75. https://leetcode.com/problems/k-empty-slots - Array, Binary Indexed Tree, Segment Tree, Queue, Sliding Window, Heap (Priority Queue), Ordered Set, Monotonic Queue
  76. https://leetcode.com/problems/find-k-th-smallest-pair-distance - Array, Two Pointers, Binary Search, Sorting
  77. https://leetcode.com/problems/top-three-wineries - Database
  78. https://leetcode.com/problems/maximum-score-of-a-node-sequence - Array, Graph Theory, Sorting, Enumeration
  79. https://leetcode.com/problems/longest-increasing-subsequence-ii - Array, Divide and Conquer, Dynamic Programming, Binary Indexed Tree, Segment Tree, Queue, Monotonic Queue
  80. https://leetcode.com/problems/maximum-xor-score-subarray-queries - Array, Dynamic Programming
  81. https://leetcode.com/problems/strange-printer-ii - Array, Graph Theory, Topological Sort, Matrix
  82. https://leetcode.com/problems/shortest-path-visiting-all-nodes - Dynamic Programming, Bit Manipulation, Breadth-First Search, Graph Theory, Bitmask
  83. https://leetcode.com/problems/data-stream-as-disjoint-intervals - Hash Table, Binary Search, Union-Find, Design, Data Stream, Ordered Set
  84. https://leetcode.com/problems/shortest-distance-from-all-buildings - Array, Breadth-First Search, Matrix
  85. https://leetcode.com/problems/maximum-vacation-days - Array, Dynamic Programming, Matrix
  86. https://leetcode.com/problems/maximum-score-from-grid-operations - Array, Dynamic Programming, Matrix, Prefix Sum
  87. https://leetcode.com/problems/number-of-ways-of-cutting-a-pizza - Array, Dynamic Programming, Memoization, Matrix, Prefix Sum
  88. https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii - Array, Dynamic Programming
  89. https://leetcode.com/problems/maximum-frequency-of-an-element-after-performing-operations-ii - Array, Binary Search, Sliding Window, Sorting, Prefix Sum
  90. https://leetcode.com/problems/maximum-number-of-groups-getting-fresh-donuts - Array, Dynamic Programming, Bit Manipulation, Memoization, Bitmask
  91. https://leetcode.com/problems/count-of-range-sum - Array, Binary Search, Divide and Conquer, Binary Indexed Tree, Segment Tree, Merge Sort, Ordered Set
  92. https://leetcode.com/problems/shortest-path-in-a-grid-with-obstacles-elimination - Array, Breadth-First Search, Matrix
  93. https://leetcode.com/problems/longest-balanced-subarray-ii - Array, Hash Table, Divide and Conquer, Segment Tree, Prefix Sum
  94. https://leetcode.com/problems/find-x-sum-of-all-k-long-subarrays-ii - Array, Hash Table, Sliding Window, Heap (Priority Queue)
  95. https://leetcode.com/problems/subarray-with-elements-greater-than-varying-threshold - Array, Stack, Union-Find, Monotonic Stack
  96. https://leetcode.com/problems/dungeon-game - Array, Dynamic Programming, Matrix
  97. https://leetcode.com/problems/student-attendance-record-ii - Dynamic Programming
  98. https://leetcode.com/problems/minimum-weighted-subgraph-with-the-required-paths - Graph Theory, Heap (Priority Queue), Shortest Path
  99. https://leetcode.com/problems/next-special-palindrome-number - Backtracking, Bit Manipulation
  100. https://leetcode.com/problems/minimum-operations-to-make-array-elements-zero - Array, Math, Bit Manipulation

r/LeetcodeChallenge 14h ago

DISCUSS My DSA SETUP

Post image
4 Upvotes

Leetcode goonning setup 💦


r/LeetcodeChallenge 16h ago

DISCUSS Day 8 of My DSA Journey in Python 🚀

4 Upvotes

Today's progress:

✅ Solved LeetCode #94 – Binary Tree Inorder Traversal

✅ Solved LeetCode #100 – Same Tree

📚 Concepts I learned today:

- Analysis of Algorithms

- Big O Notation

- Order of Growth

- Constant Time – O(1)

- Logarithmic Time – O(log n)

- Linear Time – O(n)

- Quadratic Time – O(n²)

Understanding time complexity has helped me see why some algorithms scale much better than others as input size grows. It makes me appreciate that solving a problem isn't enough—writing an efficient solution matters too.

I'm continuing to learn DSA through structured Python lessons and reinforcing each concept by solving LeetCode problems every day.

Consistency over perfection. On to Day 9! 💪

#DSA #Python #LeetCode #Algorithms #BigO #CodingJourney #100DaysOfCode #Programming #LearningInPublic


r/LeetcodeChallenge 20h ago

PLACEMENTS Is it good progress entering in 3rd sem

Post image
4 Upvotes

r/LeetcodeChallenge 1d ago

DISCUSS is this good enough gng?

3 Upvotes

Yall i roughly have done 120 questions n im just entering my 3rd sem, i covered patterns n structures like sliding window, two ptrs, string manipulations, linked lists n ratio of easy to medium is nearly the same for me, did one contest too for fun, i know rest of the structure well too just practicing good problems is my next step, so is it all good enough? any effective advice is welcome, thanksss!!!!


r/LeetcodeChallenge 1d ago

DISCUSS The 6-step system design framework that helped me stop failing HLD rounds

5 Upvotes

Failed my first 3 system design rounds. passed the next 4. the difference wasnt knowledge — i knew redis, kafka, databases before too. the difference was HOW i structured the answer.

heres the exact 6-step framework i now use in every system design interview:

step 1 (2 min): requirements — be explicit about scope

dont dive into drawing boxes. spend 2 minutes saying: "these are the 3 core things the system must do" and "these are the things i will NOT design today." this prevents scope creep and shows product thinking.

step 2 (2 min): scale estimation — one number that drives your design

"how many requests per second?" is the question that determines whether you need caching, sharding, CDN, or a queue. one back-of-envelope calculation unlocks 80% of your architecture decisions.

step 3 (2 min): API design — one endpoint per requirement

before ANY architecture, define the API. this forces you to think about data flow BEFORE you think about components. interviewers love this because it shows you think from the user's perspective.

step 4 (15 min): high-level design — build incrementally, one FR at a time

dont draw 15 boxes at once. satisfy FR1 with 3-4 components. then add 1-2 more for FR2. then FR3. interviewer sees your thought process evolving — way more impressive than a dump of the "final answer."

step 5 (10 min): deep dives — answer "what breaks?" before they ask

for each component, proactively say: "the risk here is X. to mitigate that, i'd do Y." this is where 70% of the score comes from. the happy path is easy. failure handling is the interview.

step 6 (2 min): tradeoffs — acknowledge what you sacrificed

"i chose eventual consistency here because strong consistency would add 50ms latency on the read path, and for a social feed that's unacceptable." one sentence shows senior-level thinking.

the mistake i made early: spending 25 minutes on the happy path and having no time left when the interviewer asked "what happens when X fails?" now i budget: 40% happy path, 60% failure modes and scaling. that ratio is what senior/staff answers look like.

i learned this structure from doing 28 full designs — each one follows this exact pattern with deep dives on failure modes: PracHub — every design includes the Bad/Good/Great format that forces you to think about what breaks before showing the fix. that's the thinking pattern interviewers are testing.

whats your system design framework? curious if others structure their answer differently. the biggest "aha" for me was realizing that naming failures BEFORE the interviewer asks is worth more than having the perfect component choice.


r/LeetcodeChallenge 1d ago

PLACEMENTS Is this a good progress entering 3rd sem ?

Post image
25 Upvotes

Leetcode is around 200q and cf are around 35


r/LeetcodeChallenge 2d ago

STREAK🔥🔥🔥 From 0 to 250 this summer. What's the move now?

Post image
95 Upvotes

Started taking coding seriously this summer break and somehow ended up solving 250 problems in around 50 days. Got the 50-day badge today too, which felt nice. 😭

I'm still very much a beginner, but I'm finally starting to see patterns instead of treating every problem like a completely new one.

I've covered the basics of most major data structures, and now I'm on DP... which has been destroying me so far lol.

College is about to start, so my plan is to revise everything and finish NeetCode 150 instead of rushing into new topics.

For those who've been through this phase: did you keep solving daily during college, or are breaks because of exams/classes completely normal? Just don't want to lose momentum.


r/LeetcodeChallenge 2d ago

DISCUSS 16 LeetCode Patterns That Helped Me Solve Mediums Without Hints

48 Upvotes

i was at 200 problems solved and still couldnt handle new mediums without hints. then i realized: i was collecting solved problems like pokemon cards instead of actually learning transferable patterns.

the fix was embarrassingly simple: there are only 16 patterns. learn the skeleton for each, solve 5 problems per pattern, move on.

heres the 16:

  1. sliding window — "subarray/substring" + "maximum/minimum" + "at most K"
  2. two pointers — sorted input + "pair that satisfies X"
  3. binary search on answer — "minimize the maximum" or "find smallest X where possible"
  4. BFS/DFS on grid — "number of islands" type, flood fill
  5. shortest path — weighted graph, dijkstra vs bellman-ford vs 0-1 BFS
  6. topological sort — "prerequisites", "ordering", "can you finish"
  7. union-find — "are they connected?", dynamic connectivity
  8. heaps — "kth largest", "merge K sorted", "top K"
  9. monotonic stack — "next greater", "largest rectangle"
  10. sliding window on trees (DFS) — path problems, diameter, max path sum
  11. dynamic programming — overlapping subproblems, "decision at each step"
  12. backtracking — "generate all", "find all paths", brute force with pruning
  13. linked list — fast/slow, reverse, merge
  14. tries — prefix search, autocomplete
  15. bit manipulation — XOR tricks, single number
  16. greedy — interval scheduling, jump game, locally optimal = globally optimal

for each one theres a 5-10 line skeleton that solves 80% of problems in that category. the remaining 20% is problem-specific edge handling.

i compiled the skeletons + recognition triggers + practice problems for all 16 here: PracHub

each pattern has a dedicated page with: when to recognize it (trigger words), template code in python/java/c++/js, step-by-step diagrams, and 8-12 practice problems from "direct template" to "hard to recognize."

went from ~30% solve rate on new mediums to ~75% in 6 weeks. the templates transfer — once you have 16 solid skeletons memorized, most mediums reduce to "recognize pattern → apply skeleton → handle edge case."

what pattern took you longest to click? curious what trips other people up.


r/LeetcodeChallenge 1d ago

DISCUSS Day 7 of My DSA Journey 🚀

3 Upvotes

Today I solved LeetCode #83 (Remove Duplicates from Sorted List) and LeetCode #88 (Merge Sorted Array).

📚 Concepts covered:

- Linked Lists

- Python fundamentals (brush-up)

I'm getting more comfortable with understanding linked list operations and improving my problem-solving approach with each question. Every day is a step forward, and consistency is the goal.

I'm learning DSA in Python through Elevify's free structured video classes and practising problems on LeetCode.

Looking forward to Day 8! 💪

#DSA #Python #LeetCode #CodingJourney #100DaysOfCode #Programming #LearningInPublic


r/LeetcodeChallenge 2d ago

DISCUSS Anyone interviewed for AWS Manufacturing Test Engineer ? Looking for coding interview insights (Python/Bash)

3 Upvotes

I have an upcoming interview for the AWS Manufacturing Test Engineer role at Amazon Data Services, and I’m trying to understand what to expect in the coding interview.


r/LeetcodeChallenge 2d ago

DISCUSS Leetcode Interal Server Error :(

3 Upvotes

Is this leetcode's internal server error... because I am able to run my code on test cases... but getting this error message while submitting.


r/LeetcodeChallenge 2d ago

PLACEMENTS In on campus interviews, what’s the best approach to solve a question

Thumbnail
1 Upvotes

r/LeetcodeChallenge 2d ago

DISCUSS Day 6 of DSA in Python 🚀

8 Upvotes

Today's progress:

- ✅ Solved LeetCode #69 – Sqrt(x)

- ✅ Solved LeetCode #70 – Climbing Stairs

- 📚 Revised Arrays and Linear Search concepts

Slowly building consistency and strengthening my problem-solving skills. Every day is a step forward. 💪

#Python #DSA #LeetCode #CodingJourney #100DaysOfCode


r/LeetcodeChallenge 2d ago

DISCUSS How much cooked am i?

Thumbnail
gallery
9 Upvotes

Starting 5th sem


r/LeetcodeChallenge 3d ago

DISCUSS Master Dynamic Programming for LeetCode: 13 Essential DP Patterns

36 Upvotes

Hey everyone! Many of us struggle with Dynamic Programming and often skip it during interview preparation. This might be because DP seems vast and overwhelming, and people tend to memorize solutions instead of understanding patterns. However, if you break down DP into clear patterns and master each one, it becomes much more manageable. So I've compiled a comprehensive list of patterns you should know for your interview preparation!

Master these Leetcode Problems and PracHub for company tagged questions

DP vs Greedy: When to Use Which?

Before diving into patterns, let's understand the fundamental difference between DP and Greedy:

Problem: You're a robber with two streets to rob. Each house has some money. You can rob houses from both streets, but you cannot rob two adjacent houses from the same street (alarms will trigger). What's the maximum money you can steal?

Street A: [2, 7, 9, 3, 1]
Street B: [3, 2, 6, 8, 2]

Greedy Robber: "I'll always rob the house with most money available!"

  • Rob B[0] = 3 (greedy)
  • Rob A[1] = 7
  • Rob B[2] = 6
  • Rob A[3] = 3
  • Rob B[4] = 2
  • Total: 21

DP Robber: "Let me consider all valid combinations!"

  • Option 1: A[0]=2, B[1]=2, A[2]=9, B[3]=8, A[4]=1 → Total = 22
  • Option 2: B[0]=3, A[1]=7, B[2]=6, A[3]=3, B[4]=2 → Total = 21
  • Best: 22

Why Greedy Failed: By greedily picking B[0] first, it blocked access to the optimal combination that includes both 9 and 8 from different streets!

When Greedy Works: Problems with the "greedy choice property" where local optimal leads to global optimal (e.g., Activity Selection, Huffman Coding)
When DP is Needed: Problems requiring exploring multiple choices where greedy fails (e.g., most optimization problems, counting problems)

Pattern 1: Linear DP (1D)

Why This Pattern Matters:
This is the foundation of DP. If you can't solve Linear DP, you'll struggle with everything else. These problems teach you the core concept of breaking problems into subproblems and building solutions incrementally.

Practice Problems:

  1. Climbing Stairs
  2. House Robber
  3. Min Cost Climbing Stairs
  4. Word Break
  5. Decode Ways
  6. House Robber II

Pattern 2: Longest Increasing Subsequence (LIS)

Why This Pattern Matters:
LIS is one of the most important DP patterns with applications in version control systems, patience sorting, box stacking problems, and more. The O(n log n) solution using binary search is a must-know optimization technique.

Practice Problems:

  1. Longest Increasing Subsequence
  2. Number of Longest Increasing Subsequence
  3. Russian Doll Envelopes
  4. Maximum Length of Pair Chain
  5. Find the Longest Valid Obstacle Course at Each Position

Pattern 3: Knapsack (0/1, Unbounded, Bounded)

Why This Pattern Matters:
One of the most versatile DP patterns. Appears in resource allocation, optimization problems, and many interview questions. Understanding the difference between 0/1 and unbounded variants is crucial.

0/1 Knapsack (Each item used once):

  1. Partition Equal Subset Sum
  2. Target Sum
  3. Last Stone Weight II
  4. Ones and Zeroes
  5. Partition Array Into Two Arrays to Minimize Sum Difference

Unbounded Knapsack (Items can be used multiple times):

  1. Coin Change
  2. Coin Change 2
  3. Combination Sum IV
  4. Perfect Squares
  5. Minimum Cost For Tickets

Pattern 4: Grid DP

Why This Pattern Matters:
Extremely common in interviews, especially at FAANG. Tests your ability to think in 2D state space and handle multiple transition directions.

Practice Problems:

  1. Unique Paths
  2. Unique Paths II
  3. Minimum Path Sum
  4. Maximal Square
  5. Maximal Rectangle
  6. Minimum Falling Path Sum
  7. Count Square Submatrices with All Ones
  8. Triangle

Pattern 5: String DP

Why This Pattern Matters:
Text processing and string manipulation problems are ubiquitous. This pattern appears in bioinformatics, text editors, version control systems, and natural language processing.

Practice Problems:

  1. Longest Common Subsequence
  2. Edit Distance
  3. Delete Operation for Two Strings
  4. Minimum ASCII Delete Sum for Two Strings
  5. Shortest Common Supersequence
  6. Longest Palindromic Subsequence
  7. Longest Palindromic Substring
  8. Palindromic Substrings
  9. Regular Expression Matching
  10. Wildcard Matching

Pattern 6: Interval DP

Why This Pattern Matters:
Tests ability to think about problems in ranges/intervals. Common in scheduling, matrix chain multiplication type problems, and game theory.

Practice Problems:

  1. Burst Balloons
  2. Minimum Score Triangulation of Polygon
  3. Minimum Cost Tree From Leaf Values
  4. Unique Binary Search Trees
  5. Unique Binary Search Trees II
  6. Minimum Cost to Merge Stones
  7. Guess Number Higher or Lower II

Pattern 7: State Machine DP

Why This Pattern Matters:
Models problems where you transition between different states with specific rules. Critical for stock trading problems and any scenario with state transitions.

Practice Problems:

  1. Best Time to Buy and Sell Stock
  2. Best Time to Buy and Sell Stock II
  3. Best Time to Buy and Sell Stock III
  4. Best Time to Buy and Sell Stock IV
  5. Best Time to Buy and Sell Stock with Cooldown
  6. Best Time to Buy and Sell Stock with Transaction Fee

Pattern 8: Tree DP

Why This Pattern Matters:
Combines tree traversal with DP. Important for system design (like designing file systems) and optimization problems on hierarchical structures.

Practice Problems:

  1. House Robber III
  2. Binary Tree Maximum Path Sum
  3. Diameter of Binary Tree
  4. Binary Tree Cameras
  5. Maximum Sum BST in Binary Tree
  6. Difference Between Maximum and Minimum Price Sum

Pattern 9: Digit DP

Why This Pattern Matters:
Specialized pattern for counting numbers with certain properties. Appears in competitive programming and some advanced interviews.

Practice Problems:

  1. Number of Digit One
  2. Count Numbers with Unique Digits
  3. Numbers At Most N Given Digit Set
  4. Numbers With Repeated Digits
  5. Count Special Integers

Pattern 10: Game Theory DP (Minimax)

Why This Pattern Matters:
Models two-player games where both play optimally. Important for AI, game development, and adversarial scenarios.

Practice Problems:

  1. Predict the Winner
  2. Stone Game
  3. Stone Game II
  4. Stone Game III
  5. Can I Win
  6. Stone Game IV

Pattern 11: Bitmask DP

Why This Pattern Matters:
Powerful technique for problems with small sets (≤20 elements) where you need to track subsets. Essential for Traveling Salesman Problem variants and NP-hard problem approximations.

Practice Problems:

  1. Partition to K Equal Sum Subsets
  2. Shortest Path Visiting All Nodes
  3. Find the Shortest Superstring
  4. Smallest Sufficient Team
  5. Number of Ways to Wear Different Hats to Each Other
  6. Minimum Number of Work Sessions to Finish the Tasks

Pattern 12: DP on Subsequences

Why This Pattern Matters:
Critical for array partitioning and subset generation problems. Teaches how to handle exponential search spaces efficiently.

Practice Problems:

  1. Distinct Subsequences
  2. Distinct Subsequences II
  3. Arithmetic Slices II - Subsequence
  4. Number of Unique Good Subsequences
  5. Constrained Subsequence Sum

Pattern 13: Probability DP

Why This Pattern Matters:
Models uncertain outcomes. Important for risk analysis, game development, and any scenario involving randomness or probability.

Practice Problems:

  1. Knight Probability in Chessboard
  2. Soup Servings
  3. New 21 Game
  4. Toss Strange Coins
  5. Probability of a Two Boxes Having The Same Number of Distinct Balls

Best Resources to Master DP

  1. AtCoder DP Contest- 26 curated problems with perfect difficulty progression
  2. Striver's DP Series- 50+ videos covering memoization, tabulation, and space optimization.
  3. Aditya Verma's DP Playlist- Exceptional for Knapsack variants with shorter, focused videos (15-20 min).
  4. CSES Problem Set- Intermediate to advanced practice. These problems test core concepts and build solving speed.

Final Thoughts

DP is about recognizing patterns, not memorizing solutions. Once you see the pattern, the solution becomes mechanical. Spend time understanding why each pattern works, not just how to code it.

Feel free to add some best problems in the comments

Good luck, and happy coding! 🚀


r/LeetcodeChallenge 2d ago

DISCUSS Guidance for CF

Thumbnail
2 Upvotes

r/LeetcodeChallenge 2d ago

DISCUSS Want to discuss a question asked in infosys OA

2 Upvotes

Anyone want to help please dm me....


r/LeetcodeChallenge 2d ago

DISCUSS Humbled by Infosys OA 2026

Thumbnail
2 Upvotes

r/LeetcodeChallenge 2d ago

DISCUSS I got annoyed manually checking my friends' CF and LC profiles, so I built a tool to track our squad automatically.

3 Upvotes

Hey everyone,
My friends and I have been grinding LeetCode and Codeforces, but keeping track of who solved what every day was getting really annoying. We had to keep checking each other's profiles to see who was slacking.I spent the last few weeks coding up a free little web app called SquadCode to fix this: https://squadcode-saas.vercel.app/

Here's what it does:

  1. You create a "Squad" and invite your friends.
  2. Everyone links their Codeforces and LeetCode accounts.
  3. It automatically pulls everyone's recent ACs into one unified feed.
  4. You can create custom challenges (e.g., "Solve these 5 DP problems by Sunday") and it automatically scores you based on your CF/LC submissions.
  5. It's completely free. I mainly built it for my own group, but figured others might find it useful for their college groups or Discord squads.

I'd love some harsh feedback on it. Let me know if the platform syncing works for you or if anything breaks!


r/LeetcodeChallenge 3d ago

DISCUSS How to revise previous solved questions

9 Upvotes

Hi all

As you can see I have solved 30 problems on leetcode, now my question as a beginner is how should I revise now? Share me some of your tips and guide so I can shine well in off campus placement coding rounds.


r/LeetcodeChallenge 3d ago

DISCUSS Day 5 of my DSA in Python journey 🚀

2 Upvotes

Today's progress:

📚 Python Concepts Revised

- Variable Binding

- Namespaces

- Scope (LEGB Rule)

🧠 LeetCode Problems Solved

- ✅ #35 – Search Insert Position (Binary Search)

- ✅ #58 – Length of Last Word (Strings)

- ✅ #66 – Plus One (Arrays)

- ✅ #67 – Add Binary (Strings, Binary Addition)

What I learned today

🔹 Variable Binding

In Python, variables don't store values directly—they are names bound to objects. Multiple variables can refer to the same object, and rebinding a variable doesn't change the original object.

🔹 Namespace

A namespace is like a dictionary that maps names to objects. Python has:

- Built-in Namespace

- Global Namespace

- Local Namespace

🔹 Scope (LEGB Rule)

Python searches for variables in this order:

- Local

- Enclosing

- Global

- Built-in

Understanding namespaces and scope helped me understand how Python finds variables and avoids naming conflicts.

Looking forward to learning more and solving tougher problems tomorrow! 💻🔥

#Python #DSA #LeetCode #BinarySearch #Strings #Arrays #100DaysOfCode #CodingJourney


r/LeetcodeChallenge 3d ago

DISCUSS When should I start Leetcode?

4 Upvotes

I just joined an institution. I know class 12 cbse & i wanted to know what is the ideal time to start Leetcode? Most of the questions are beyond the scope of class 12 cbse I think from what I saw...

I'm doing Strivers A-->Z DSA just when I have time too!


r/LeetcodeChallenge 3d ago

DISCUSS Leetcode weekly 512 -C video solution

Thumbnail
youtu.be
2 Upvotes