Red-Green-Code

Deliberate practice techniques for software developers

  • Home
  • About
  • Contact
  • Project 462
  • CP FAQ
  • Newsletter

LeetCode Tip 23: Learning Algorithms and Data Structures

By Duncan Smith Jun 14 0

LeetCode 2023

Most LeetCode problems require some knowledge of algorithms and data structures. But LeetCode problems are also a way to learn algorithms and data structures. So there’s a symbiotic relationship between the problems and the knowledge required to solve them.

Reading a textbook chapter about binary search will help you understand the principles behind it, how to analyze it mathematically, and the steps required to implement it. But it’s difficult to understand binary search well without solving binary search problems. Solving a simple binary search problem like LeetCode 704 is a good way to learn the fundamentals of the algorithm. From there, you can move on to harder problems where you have to integrate the binary search algorithm into a larger solution. As you’re solving a harder problem, you might go back to the textbook description of an algorithm to clarify the details, and then use that information to improve your solution. In this way, you can set up a virtuous cycle where solving problems helps you understand the algorithm, and the algorithm helps you solve problems more effectively.

Writing detailed model solution descriptions can also help you learn algorithms and data structures better. Just as writing a model solution clarifies your understanding of a specific LeetCode problem, it can also help you understand the general principles behind an algorithm. As you write your solutions, use correct terminology and explain how your solution applies a general algorithm to the specific problem you’re writing about. This will make it easier to move on to the next algorithm in a topic-wise list, since your algorithm skills and knowledge won’t be closely tied to one problem.

Besides applying an algorithm to a familiar problem, another key LeetCode skill is selecting the correct algorithm for a problem you haven’t seen before. As you learn algorithms and write solution descriptions, you can take notes from that perspective. For example, you can remind yourself that when the input data for a problem is sorted or can be sorted, consider using binary search. When you’re solving a topic-wise list of problems, you aren’t practicing this skill directly, since you already know which algorithm the problems require. But even with this type of practice, you can look for similarities between the problems, and include these in your notes. Then, when you need to select an algorithm for an unfamiliar problem, you can look through your list of heuristics to get ideas about which algorithm to use.

This year, I’m publishing a series of tips for effective LeetCode practice. To read the tips in order, start with A Project for 2023.

Categories: LeetCode

Prev
Next

Stay in the Know

I'm trying out the latest learning techniques on software development concepts, and writing about what works best. Sound interesting? Subscribe to my free newsletter to keep up to date. Learn More
Unsubscribing is easy, and I'll keep your email address private.

Getting Started

Are you new here? Check out my review posts for a tour of the archives:

  • 2023 in Review: 50 LeetCode Tips
  • 2022 in Review: Content Bots
  • 2021 in Review: Thoughts on Solving Programming Puzzles
  • Lessons from the 2020 LeetCode Monthly Challenges
  • 2019 in Review
  • Competitive Programming Frequently Asked Questions: 2018 In Review
  • What I Learned Working On Time Tortoise in 2017
  • 2016 in Review
  • 2015 in Review
  • 2015 Summer Review

Archives

Recent Posts

  • Do Coding Bots Mean the End of Coding Interviews? December 31, 2024
  • Another Project for 2024 May 8, 2024
  • Dynamic Programming Wrap-Up May 1, 2024
  • LeetCode 91: Decode Ways April 24, 2024
  • LeetCode 70: Climbing Stairs April 17, 2024
  • LeetCode 221: Maximal Square April 10, 2024
  • Using Dynamic Programming for Maximum Product Subarray April 3, 2024
  • LeetCode 62: Unique Paths March 27, 2024
  • LeetCode 416: Partition Equal Subset Sum March 20, 2024
  • LeetCode 1143: Longest Common Subsequence March 13, 2024
Red-Green-Code
  • Home
  • About
  • Contact
  • Project 462
  • CP FAQ
  • Newsletter
Copyright © 2025 Duncan Smith