Chapter 63: DSA Exercises

Here is a detailed, practical and structured set of DSA Exercises — exactly the kind of list and explanations a good teacher would give you when you ask:

“Give me good exercises to really learn DSA.”

I divided them by topic, from beginner-friendly to medium-hard, with realistic difficulty order, what concept they teach, and why they are worth solving.

Each problem has:

  • Name / LeetCode number (if available)
  • Core concept it teaches
  • Difficulty level (according to most students’ experience)
  • Recommended order

Beginner Level Exercises (Must do first – build intuition)

  1. Find the maximum element in an array → Teaches: basic loop, comparison Difficulty: ★☆☆
  2. Find second largest element in array (without sorting) → Teaches: single pass, tracking two variables Difficulty: ★★☆
  3. Reverse an array in-place (without extra space) → Teaches: two pointers, swapping Difficulty: ★★☆
  4. Check if array is palindrome → Teaches: two pointers from both ends Difficulty: ★★☆
  5. Move all zeros to the end (maintain relative order of non-zeros) → Teaches: two pointers / one pass Difficulty: ★★☆ (LeetCode #283 – Move Zeroes)
  6. Remove duplicates from sorted array (in-place) → Teaches: two pointers, overwriting Difficulty: ★★☆ (LeetCode #26)
  7. Rotate array to the right by k steps (in-place) → Teaches: multiple approaches (reverse trick is best) Difficulty: ★★★ (LeetCode #189)
  8. Majority Element (element appears > n/2 times) → Teaches: Boyer-Moore Voting Algorithm (O(n) time, O(1) space) Difficulty: ★★★ (LeetCode #169)
  9. Best Time to Buy and Sell Stock (one transaction) → Teaches: single pass, keeping track of minimum so far Difficulty: ★★☆ (LeetCode #121)
  10. Kadane’s Algorithm – Maximum Subarray Sum → Teaches: dynamic programming one-liner intuition Difficulty: ★★★ (LeetCode #53)

Intermediate Level Exercises (very important – do 70–80% of these)

Two Pointers / Sliding Window

  1. 3Sum (find all triplets sum to zero) → Teaches: sorting + two pointers pattern Difficulty: ★★★★ (LeetCode #15)
  2. Container With Most Water → Teaches: two pointers moving from ends Difficulty: ★★★ (LeetCode #11)
  3. Longest Substring Without Repeating Characters → Teaches: sliding window + hash set/map Difficulty: ★★★★ (LeetCode #3)
  4. Minimum Window Substring → Teaches: sliding window with two pointers + counter Difficulty: ★★★★★ (LeetCode #76)
  5. Longest Repeating Character Replacement → Teaches: sliding window with character frequency Difficulty: ★★★★

Binary Search & Binary Search on Answer

  1. Search in Rotated Sorted Array → Teaches: modified binary search Difficulty: ★★★★ (LeetCode #33)
  2. Find Minimum in Rotated Sorted Array → Teaches: binary search on unsorted rotated array Difficulty: ★★★★ (LeetCode #153)
  3. Koko Eating Bananas → Teaches: binary search on answer pattern Difficulty: ★★★★ (LeetCode #875)
  4. Capacity To Ship Packages Within D Days → Teaches: binary search on answer (very common pattern) Difficulty: ★★★★ (LeetCode #1011)
  5. Aggresive Cows / Book Allocation / Painter’s Partition → Teaches: classic binary search on answer (very frequent in India placements)

Linked List

  1. Reverse a Linked List (iterative + recursive) → Teaches: pointer manipulation Difficulty: ★★☆
  2. Merge Two Sorted Lists → Teaches: dummy node technique Difficulty: ★★☆ (LeetCode #21)
  3. Detect Cycle in Linked List (Floyd’s cycle detection) → Teaches: fast & slow pointer Difficulty: ★★★ (LeetCode #141)
  4. Remove Nth Node From End of List → Teaches: two pointers with gap Difficulty: ★★★ (LeetCode #19)
  5. LRU Cache (design question) → Teaches: hash map + doubly linked list Difficulty: ★★★★★ (LeetCode #146)

Intermediate-Advanced Exercises (very high value)

  1. Merge k Sorted Lists → Teaches: priority queue / min-heap Difficulty: ★★★★ (LeetCode #23)
  2. Kth Largest Element in an Array → Teaches: quickselect / min-heap Difficulty: ★★★★ (LeetCode #215)
  3. Number of Islands (DFS/BFS on grid) → Teaches: graph traversal on matrix Difficulty: ★★★★ (LeetCode #200)
  4. Word Ladder → Teaches: BFS on graph (word transformation) Difficulty: ★★★★★ (LeetCode #127)
  5. Course Schedule (detect cycle + topological sort) → Teaches: DFS/BFS cycle detection + topological order Difficulty: ★★★★★ (LeetCode #207)

Tips – How to practice these examples effectively

  1. First solve without looking at solution (even if it takes 1–2 hours)
  2. Write clean code — good variable names, comments
  3. Always analyze:
    • Time complexity (best / average / worst)
    • Space complexity
    • Can we optimize space? (very common follow-up)
  4. Dry run on paper with 4–5 small test cases
  5. Think of edge cases: empty array, single element, all same elements, already sorted, reverse sorted, duplicates, etc.
  6. After solving → read official solution / discuss on LeetCode/Reddit

Would you like me to:

  • Give you 50–70 most important problems categorized by topic
  • Explain any one specific problem from the list above in full detail (with code + dry run)
  • Make a personalized practice plan (beginner / intermediate / advanced)
  • Focus on one topic (arrays, DP, graphs, binary search, etc.) with 5–8 strong problems

Just tell me what you want next — I’ll continue in the same detailed, teacher-like style 😊

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *