Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

These 17 coding challenges exercise different kinds of problem-solving: breaking a task into parts, choosing between algorithms, tracking state, proving a shortcut is safe, and testing edge cases. They are useful practice for learners and interview preparation, but the list is not proof that solving these exact problems improves general critical-thinking ability. Use them to make your reasoning visible, not just to produce a passing answer.

How to practice so the challenge tests your reasoning

Before opening an editor, turn the prompt into a small specification. Then solve it in stages:

  1. Restate the task. Write down the input, the required output, and what counts as a valid answer. Note whether the input can be empty, contain duplicates, or be unusually large.
  2. List constraints and assumptions. Clarify such details as whether numbers are consecutive, whether a path must be shortest, and whether a cache operation must be constant-time. If the prompt does not say, identify the assumption your solution uses.
  3. Make a baseline. Describe the simplest correct approach in plain language, even if it is slow. A baseline gives you something to compare against and helps separate correctness from optimization.
  4. Choose tests before coding. Include an ordinary case, a boundary case, and an adversarial case. For example, test an empty or one-item input where allowed, repeated values, an already ordered input, and a case that forces the worst behavior you expect.
  5. Compare alternatives. State the time and extra-space costs of each approach. Explain what the faster method stores or assumes in exchange for its improvement.
  6. Explain why it works. Identify an invariant, a state transition, or a proof of the greedy choice. Then trace one example by hand and only then implement.
  7. Review failures as evidence. When a test fails, find the smallest input that reproduces it. Ask whether the mistake is in the model, the invariant, a boundary condition, or the code.

Keep a short record for each problem: baseline, improved idea, complexity, key correctness argument, and the test that caught your hardest bug. This turns a collection of solved prompts into reusable patterns.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Foundations: arrays, maps, stacks, and pointers

1. Find the missing number in an array

Given a range of consecutive integers with one value absent, find the missing value. First establish the exact range and whether there is exactly one omission. Compare summing the expected range and subtracting the observed sum with an XOR-based approach. The sum method highlights a numerical invariant; XOR cancels matching values and avoids ordinary addition overflow concerns in fixed-width integer contexts. Test the smallest permitted range and omissions at both ends. Do not apply either method if duplicates or multiple missing values are allowed without revisiting the specification.

#1 Best Overall
SUQJOY Magnetic Dry Erase Markers, Fine Tip Whiteboard Markers with Eraser Caps, Low Odor, 12 Assorted Colors, for Fridge Calendar, 12 Count
  • 12 Assorted Colors for Clear Color Coding:Includes 12 bright assorted colors that make it easy to organize schedules, highlight priorities, and keep notes easy to read on fridge calendars, planners, and whiteboards.
  • Magnetic Markers Stay Right Where You Need Them:Strong magnetic caps attach securely to whiteboards, refrigerators, lockers, and other metal surfaces, so your markers stay visible, organized, and easy to grab.
  • Built-In Eraser Caps for Quick Corrections:Each marker comes with an eraser cap for fast touch-ups and clean corrections during planning, note-taking, meetings, and daily task tracking.
  • Low Odor Ink with Smooth Writing and Easy Wiping:Low odor ink writes smoothly, dries quickly, and wipes clean from dry erase surfaces with less smudging, helping keep boards neat and easy to maintain.
  • Great for Whiteboards, Glass, Mirrors, and Calendars:Designed for use on whiteboards and other non-porous surfaces such as glass and mirrors, making this set a practical choice for home, office, and refrigerator planning.

2. Two Sum

Find two values whose sum equals a target. The direct approach checks pairs and takes O(n²) time with O(1) extra space. A hash map can reduce expected lookup work to O(n) time using O(n) space. Think carefully about whether to store a value before or after checking its complement: checking first avoids pairing an item with itself unless the input contains a second matching item. Test duplicates, negative values, no solution, and a target requiring the same value twice.

3. Valid parentheses

Determine whether opening and closing brackets are correctly matched and nested. A stack records unmatched opening symbols; each closing symbol must match the stack top, and the stack must be empty at the end. The reasoning is about nested state, not just counting characters: a string can have equal numbers of each bracket and still be invalid. Test a premature close, a missing close, an empty string if allowed, and mixed bracket types.

4. Reverse a linked list

Reverse the links in a singly linked list without losing access to the rest of the list. The iterative method maintains previous, current, and next references, saving next before redirecting the current link. The key invariant is that the processed prefix is already reversed and the unprocessed suffix remains reachable. Compare this with recursion: recursive reasoning can be concise, but uses call-stack space and may encounter depth limits on long lists. Test empty, one-node, and multi-node lists; verify both the new head and termination of the final link.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Pattern building: windows, centers, and two pointers

5. Palindromic substrings

Count or find palindromic substrings, making sure the prompt distinguishes substrings from distinct palindrome values. Expanding around each center checks outward while characters match; there are odd-length centers at characters and even-length centers between characters. This approach is commonly O(n²) time and O(1) extra space, aside from output. Dynamic programming records whether smaller intervals are palindromes and reuses that result, typically trading O(n²) space for stored subproblems. Test repeated characters and even-length palindromes, which reveal missed centers.

6. Container With Most Water

Given vertical lines at positions, choose two that maximize width multiplied by the shorter height. A brute-force scan considers every pair. The two-pointer method starts at the ends and moves the pointer at the shorter line. Its justification matters: keeping the shorter boundary while reducing width cannot improve the area, so a better candidate must discard that limiting boundary. Test steadily increasing heights, equal heights, and a tall line paired with a very short one. Do not move a pointer arbitrarily; the movement rule is the heart of the algorithm.

7. Find all anagrams in a string

Find positions where a window in one string has the same character frequencies as a target string. A sliding window avoids recounting each candidate from scratch: add the incoming character and remove the outgoing one as the window advances. Frequency accounting must match the character model and alphabet assumed by the prompt. Test repeated letters, a target longer than the source, overlapping matches, and characters outside any assumed lowercase alphabet.

Rank #2
Scribbledo Small Dry Erase Board with Lines for Kids, 9x12 Double Sided
  • DOUBLE SIDED FOR TWO WAYS TO LEARN: One side is ruled for neat handwriting practice and letter formation, while the plain reverse side is perfect for math problems, drawing, and free form creativity.
  • LINED CRISP SURFACE THAT WIPES CLEAN: The smooth dry erase coating wipes clean with a cloth or eraser, so kids can practice the same letters and numbers over and over without smudging or ghosting.
  • 9 X12 INCH RIGHT SIZED FOR LITTLE HANDS: At 9 by 12 inches, this small whiteboard is easy for young students, even toddlers, hold, carry in a backpack, and set flat on a desk or table for handwriting drills.
  • MULTFUNCTIONAL EDUCATIONAL TOOL FOR DAILY PRACTICE: A solid board base supports repeated writing and erasing sessions at home or in the classroom, standing up to the wear of everyday handwriting practice.
  • STURDY MASONITE BUILD FOR CLASSROOM AND HOMESCHOOL USE: Made with safe, non toxic, skin friendly materials and a reusable surface that helps students and teachers save on paper and notebook costs.

8. Trapping Rain Water

Given bar heights, calculate how much water is trapped after rain. A boundary-based formulation says the water above a position depends on the shorter of the tallest boundary to its left and right, minus its own height, when positive. A two-pointer method can compute this while advancing the side whose maximum boundary is smaller, maintaining the relevant maxima. The exercise is to justify why the opposite boundary is sufficient at that step. Test flat terrain, monotonic heights, a single basin, and zero-height boundaries.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Graphs and search: shortest paths, dependencies, and backtracking

9. Word Ladder

Given a start word, an end word, and an allowed dictionary, find a shortest sequence in which adjacent words differ by one letter. Model each valid word as a graph node and each one-letter change as an edge. Breadth-first search finds a shortest path when all transitions have equal cost. The details that change answers include whether the end word must be in the dictionary and whether the sequence length counts words or transformations. Track visited words so cycles do not cause repeated work. Test an unreachable target and a case with multiple paths of the same length.

10. Course Schedule

Given courses and prerequisite relationships, decide whether all courses can be completed. Represent prerequisites as a directed graph; a cycle means a course ultimately depends on itself. Use depth-first cycle detection or a topological-ordering method such as repeatedly removing courses with no remaining prerequisites. Be explicit about edge direction, since reversing it can still look plausible while changing the interpretation. Test no prerequisites, a simple chain, a disconnected cycle, and duplicate relationships if the input permits them.

11. Word Search

Search for a word in a two-dimensional character grid by moving between adjacent cells, typically without reusing a cell in one path. Depth-first search explores candidate paths, and backtracking restores a cell’s availability when a branch fails. The state is the current grid position, the next character index, and the set of cells already used in that path. Test a one-character word, a word longer than the grid can support, repeated letters, and a path that would succeed only if a cell were incorrectly reused.

Data-structure design and divide-and-conquer

12. Least Recently Used cache

Design a cache with get and put operations that evicts the least recently used item at capacity. A hash map finds entries quickly; a doubly linked list orders them by recency, allowing a touched entry to move to the front and the least recent entry to be removed from the tail. The design targets O(1) get and put operations. Specify what a get miss returns, how updating an existing key affects recency, and what happens at zero capacity if that case is allowed. Test repeated access, overwrite, and eviction order.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

13. Merge k sorted lists

Merge several sorted lists into one sorted sequence. Pairwise merging is a useful baseline. A min-heap keeps the smallest current head among the lists available, producing a typical O(N log k) approach for N total elements and k lists, with heap size up to k. Another option is divide-and-conquer pairwise merging. Compare the costs and implementation complexity, and test empty lists, one list, duplicates, and lists of very different lengths.

Rank #3
Dry Erase Lined Whiteboard for Kids, White Board with Lines for Writing, Handwriting Practice Board for School and Homeschool Supplies
  • Dry Erase Lined Whiteboard: Double-sided 11x8.5 inch dry erase board, featuring lined and unlined surfaces for versatile use
  • Double-Sides: One side with lines, perfect for practicing handwriting, spelling, and sentence formation. The other side is a blank whiteboard, ideal for drawing, brainstorming, and creative expression.
  • Reusable: Durable construction ensures long-lasting use, suitable for repeated writing and erasing.
  • Various Learning Activities: Includes a marker for easy writing and erasing, promoting interactive learning and creativity. Versatile educational tool suitable for various learning activities and subjects.
  • Suitable for Kids: Suitable for children of all ages, from preschoolers learning to write to older students practicing spelling and drawing. Perfect addition to homeschooling supplies, classrooms, or tutoring sessions.

14. Count inversions

Count pairs of positions i < j where the value at i is greater than the value at j. A quadratic pair scan gives a clear baseline. A modified merge sort counts inversions while combining sorted halves: when a right-side value precedes remaining left-side values, it contributes multiple inversions at once. This is a divide-and-conquer improvement to O(n log n) time. Be precise about strict versus non-strict comparison; equal values are not inversions under the usual definition. Test sorted, reverse-sorted, and duplicate-heavy inputs.

15. Maximal Rectangle in a Binary Matrix

Find the largest all-one rectangle in a binary matrix. Treat each row as the base of a histogram: for every column, carry forward the height of consecutive ones ending at that row. Then solve the largest-rectangle-in-a-histogram problem with a monotonic stack. This combines matrix traversal with a stack invariant about increasing heights. Test all zeros, all ones, a single row, a single column, and a rectangle whose best area appears below the first row.

Constraint reasoning and careful validation

16. Sudoku validator

Check whether a Sudoku board violates row, column, or subgrid constraints. Traverse cells while tracking seen digits in each relevant row, column, and subgrid. A subgrid index can be derived from the row and column coordinates, but validate the board dimensions and symbols according to the prompt rather than assuming a complete standard puzzle. Distinguish a valid partial board from a board that has a unique solution: validation alone does not establish solvability or uniqueness. Test duplicates in each constraint type and empty cells.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

17. First missing positive

Find the smallest positive integer absent from an unsorted array. Sorting is an understandable baseline, generally O(n log n). The classic in-place indexing approach places each value x in the position associated with x when x is within the range 1 through n, then scans for the first mismatch. It can achieve O(n) time and O(1) extra space, but requires careful bounds checks and a swap loop that always makes progress. Ignore or safely handle values outside the useful range. Test negatives, zero, duplicates, an already complete prefix, and an array containing every value from 1 through its length.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

A sensible order for working through the set

Difficulty depends on your experience and language, but this sequence builds reusable patterns rather than simply increasing code length:

  • Foundations: missing number, Two Sum, valid parentheses, reverse a linked list.
  • Pattern building: palindromic substrings, Container With Most Water, find all anagrams, Trapping Rain Water.
  • Graphs and search: Word Ladder, Course Schedule, Word Search.
  • Data-structure design: LRU cache, merge k sorted lists, maximal rectangle.
  • Optimization and proof: count inversions, first missing positive, Sudoku validation.

Once you can solve a challenge, revisit it in another language or implement the alternative approach. A second implementation is especially useful when the first solution relies on a language-specific collection or hides an important invariant.

Rank #4
SEWACC 12 Colors Erasable Liquid Pen for Led Boards Acrylic Surfaces
  • Core Creativity: This 12-color erasable pen set gives you a simple way to make LED board drawings, doodles, and message displays look brighter and more eye-catching. the assorted colors help your notes, signs, and artwork stand out while keeping the look fun and easy to change
  • Smooth Ink Flow: Made as liquid markers with plastic bodies, these pens are designed for steady writing and drawing on illuminated boards and acrylic surfaces. the quick-drying ink helps reduce smears, so your lines stay cleaner and your finished work looks more polished
  • Multi-Surface Use: Use these dry erase markers on LED writing boards, acrylic boards, whiteboards, blackboards, and other common display surfaces for home notes, routine organization, or casual . One set gives you flexible use across different boards without switching tools
  • Easy to Handle: the .1 in body is easy to hold and control, making it more comfortable for everyday writing, tracing, and coloring. the compact size also makes the set simple to keep in a drawer, pencil cup, or craft bag for quick access
  • Set Value: Each package includes 12 colors, giving you a ready-to-use supply for color coding, family activities, gift- kits, or everyday doodling. with multiple colors in one set, it is easier to keep projects organized and add variety without buying separate markers

Where to find more exercises

For short, practical exercises, EMKC organizes challenges by difficulty and describes support for 17 languages. Its examples include string reversal, frequency counting, Fibonacci, recursive sums, invalid JSON repair, and Roman-numeral conversion. Codewars offers community-created kata, browser test cases, peer solutions, ranks from beginner to expert, and support for 55+ languages. Those language and platform details can change, so check the current service pages before choosing based on a particular language or feature.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If you prefer a physical collection, Exercises for Programmers: 57 Challenges to Develop Your Coding Skills by PragProg is a larger challenge set. Confirm current availability and price with the seller; neither is fixed here. Seventeen exercises are a starting set, not a ceiling.

Or skip the browser setup

If one of your exercises is to capture a webpage as a test artifact, ScreenshotNeo offers a one-call screenshot API. The code below saves a WebP response; replace the sample URL and supply your API key. See the ScreenshotNeo API documentation for request options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers identify the page verdict and whether the request was billed. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots. See ScreenshotNeo for details. Sign up for the free plan.

Frequently Asked Questions

Do I need to solve every challenge in the same programming language?

No. Solving in a familiar language first can help isolate the algorithm; reimplementing later in another language can expose assumptions about collections, integer behavior, or recursion.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Should I memorize these solutions for coding interviews?

Memorize the patterns and correctness arguments, not a fixed implementation. Interview prompts often alter constraints, and those changes can invalidate a memorized approach.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.