SystemTutor
About
Sign in
Loading course documentation…
SystemTutor

COURSES

  • Data Structures & Algorithms
  • CSS MasterclassNew course
  • System DesignNew course

PRACTICE

  • Algorithm practice
  • CSS practice

LEGAL

  • Privacy Policy
  • Terms of Service
  • About

© 2026 SystemTutor. All rights reserved.

Built with 🫶 by Shatlyk

Course Overview
Algorithm PerformanceBig O & Time ComplexitySpace ComplexityLogarithms and ComplexityProblem Solving ApproachAlgorithm Efficiency and Problem Solving
Big O Notation

Problem Solving Approach

Master a structured 5-step framework for algorithmic problem solving: understand the problem, explore concrete examples, break it down, solve or simplify, and look back to refactor.

A request to “count the characters in a string” leaves several decisions open. Does A count with a? Does a space count? Use one example to carry the same decisions from the problem statement into the code and its tests.

The five steps

The problem-solving steps are to clarify the problem, try examples, break it down, implement a solution, and review it.

1. Understand the problem

For this example, count English letters and digits, treating uppercase and lowercase letters as equal. Ignore punctuation, whitespace, and other characters. Return a mapping from each accepted character to its count. Return an empty mapping for a non-string input.

The word alphanumeric can mean different things in different languages. The explicit English-letter and digit rule makes the expected result the same in both versions below.

2. Explore concrete examples

InputExpected countsWhat it tests
"Aa!"a → 2Case and punctuation
"B2 b2"b → 2, 2 → 2Digits, repeats, and spaces
"" or "!"Empty mappingNo characters to count
The number 42Empty mappingNon-string input

3. Break the problem down

Start with an empty mapping. Visit each original character once. If it is an English letter or digit, convert it to lowercase and add one to its count. A missing entry starts at zero.

Trace "Aa!" by hand. The first letter creates the entry a → 1. The second updates it to a → 2. The final character leaves that count unchanged.

4. Solve or simplify

If the filtering rule is getting in the way, first count a string containing only lowercase letters. Once "aba" produces a → 2, b → 1, add filtering and run the mixed-input cases.

function charCount(text) {
  const counts = {};
  if (typeof text !== "string") return counts;

  for (const character of text) {
    if (!/[A-Za-z0-9]/.test(character)) continue;
    const key = character.toLowerCase();
    counts[key] = (counts[key] ?? 0) + 1;
  }

  return counts;
}

5. Look back and refactor

Six refactoring checks cover correctness, clarity, performance, modularity, language conventions, and alternatives.

Trace "éA2" before changing the filter. Both versions should return counts for a and 2. Checking the original character before converting case keeps this behavior consistent. Keep this example as a test if you extract the filter into a helper.

For input of length n, the loop uses O(n) time. The result has at most 36 keys, one per lowercase English letter or digit. With that fixed alphabet, even the result occupies O(1) entries. If the allowed alphabet can grow, report O(k) entries for k distinct characters.

Key Takeaways

  • A concrete input and expected output can settle an ambiguous requirement.
  • Trace one ordinary case and one boundary case before writing code.
  • After refactoring, run the same examples and recheck the complexity of the code you actually wrote.

How is this lesson?

Previous lessonLogarithms and ComplexityNext lessonAlgorithm Efficiency and Problem Solving
Edit on GitHubReport on GitHub
On this page
%

On this page

The five steps1. Understand the problem2. Explore concrete examples3. Break the problem down4. Solve or simplify5. Look back and refactorKey Takeaways