This section focuses on common patterns and strategies that can simplify solving complex problems. It provides explanations and links to relevant questions. Here is the initial structure:


Techniques:

  1. Sliding Window
    • Description: Efficient for problems involving subarrays or substrings.
    • Steps to Solve: Define the window, expand/shrink it based on conditions.
    • Practice Problems:
      • Find the maximum sum of a subarray of size k.
      • Longest substring without repeating characters.
  2. Two Pointers
    • Description: Ideal for problems involving pairs or finding optimal solutions.
    • Steps to Solve: Use two pointers starting at different positions.
    • Practice Problems:
      • Merge two sorted arrays.
      • Container with most water.
  3. Binary Search on Answer
    • Description: Effective for optimization problems with a monotonic function.
    • Steps to Solve: Define the search space, check mid-point, and adjust bounds.
    • Practice Problems:
      • Minimize the maximum distance to gas stations.
      • Split array into k subarrays with minimized largest sum.
  4. Dynamic Programming
    • Description: Break down problems into smaller overlapping subproblems.
    • Steps to Solve: Define the state, recursion, and memoization.
    • Practice Problems:
      • Longest increasing subsequence.
      • Coin change problem.
  5. Greedy Algorithms
    • Description: Build up solutions piece by piece, always choosing the best current option.
    • Steps to Solve: Identify the greedy choice and prove its validity.
    • Practice Problems:
      • Activity selection problem.
      • Minimum number of platforms required at a railway station.
  6. Backtracking
    • Description: Explore all possibilities by building a solution incrementally.
    • Steps to Solve: Add constraints and backtrack when invalid.
    • Practice Problems:
      • N-Queens problem.
      • Generate all subsets of a set.