Categorygithub.com/lechuhuuha/go-leet-code
repositorypackage
0.0.0-20241202101210-cf6782c561c0
Repository: https://github.com/lechuhuuha/go-leet-code.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

How to Solve LeetCode and Similar Problems

This guide outlines the key steps and mindset for approaching and solving problems on platforms like LeetCode. It is primarily focused on easy and medium problems.


Problem-Solving Process

  1. Identify the Problem Type

    • Determine which algorithm or data structure the problem expects.
    • Problems often disguise the algorithm using real-world analogies (e.g., cities, networks, brackets).
  2. Implement the Algorithm

    • Directly translate the algorithm to code.
    • Feed the given input into the algorithm and solve.
  3. (For Hard Problems) Modify Algorithms

    • Apply tweaks or combine multiple algorithms to solve more complex problems.
    • Example: Combining BFS and backtracking.

Recognizing Problem Patterns

  • Pattern Matching: Problems often use everyday concepts to hide their underlying algorithm:
    • Example 1: "Find the shortest route between cities" → Graph Problem (BFS).
    • Example 2: "Check if brackets are balanced" → Stack Problem.

Key Tip:

Solve problems tagged with specific algorithms or data structures to get familiar with these patterns.


How to Get Good at LeetCode

  1. Study Common Algorithms and Data Structures

    • Examples: BFS, DFS, two-pointer technique, dynamic programming, heaps, stacks, etc.
  2. Practice Implementation

    • Write and reimplement these algorithms many times.
  3. Solve Tagged Problems

    • Focus on problems tagged with the algorithms/data structures you’ve studied.
    • Build familiarity by solving these repeatedly.

Building Problem-Solving Intuition

  • The more problems you solve, the better you’ll get at recognizing patterns.
  • Start with easy and medium problems. Hard problems require additional experience.

Example Keywords to Identify Algorithms

Real-World Problem DescriptionLikely Algorithm or Data Structure
Find shortest route between citiesBFS / Graph
Check for valid expressions with bracketsStack
Find the maximum subarray sumSliding Window
Group similar items based on common propertiesHashMap or Union-Find

Summary:

  • Focus on learning common patterns in problems.
  • Solve tagged problems to practice and reinforce your knowledge.
  • Over time, patterns will become intuitive, making easy and medium problems straightforward.