Problem-Solving Framework

beginner10 min

The 4-Step Framework

Under time pressure, skipping steps costs more than it saves. Use the same loop every problem: Understand, Plan, Execute, Review.

Step 1: Understand the Problem

  • Read the problem statement carefully
  • Identify input/output format
  • Note constraints and edge cases
  • Ask clarifying questions if needed
  • Write down what you understand in your own words

Step 2: Plan Your Solution

  • Think of a brute force approach first
  • Identify patterns or data structures that could help
  • Consider time and space complexity
  • Write pseudocode or draw diagrams
  • Think of edge cases and how to handle them

Step 3: Execute Your Plan

  • Implement your solution step by step
  • Test with small examples first
  • Handle edge cases explicitly
  • Write clean, readable code
  • Add comments for complex logic

Step 4: Review and Optimize

  • Test with the given examples
  • Check for bugs and edge cases
  • Analyze time and space complexity
  • Look for optimization opportunities
  • Consider alternative approaches

Example: Two Sum Problem