The Top 20 Software Engineering Interview Problems
Java, Python, and Rust solutions for clear, correct interview practice
Introduction
This is a practical briefing book for the 20 programming problems with the highest study value in a general software engineering interview. The ranking is a study-priority judgment based on frequency, pattern coverage, and suitability for a 45–60 minute interview—not a claim about an exact employer-wide question count.
The goal is not to memorize 20 isolated answers. It is to recognize a small set of reusable moves: index values in a hash map, shrink a sliding window, maintain a monotonic search interval, scan sorted data with two pointers, explore a graph once, and define a dynamic-programming state precisely.
Each chapter gives you:
- a crisp restatement and questions to clarify;
- minimal Java, Python, and Rust solutions suitable for live typing;
- a worked example and, where useful, a diagram;
- the invariant that makes the algorithm correct;
- high-value test cases;
- time and space complexity; and
- optional improvements and follow-ups to discuss only after the baseline works.
The complete programs and tests are included from language directories under src/; the book does not duplicate them. Use the Java, Python, and Rust tabs in each chapter to choose an implementation. Edit a source file and the next Quarto render picks up the change.
The ranked twenty
| Rank | Problem | Primary pattern | Target time |
|---|---|---|---|
| 1 | Two Sum | Hash map | \(O(n)\) |
| 2 | Merge Intervals | Sort + scan | \(O(n\log n)\) |
| 3 | Longest Substring | Sliding window | \(O(n)\) |
| 4 | Valid Parentheses | Stack | \(O(n)\) |
| 5 | Binary Search | Divide search space | \(O(\log n)\) |
| 6 | Three Sum | Sort + two pointers | \(O(n^2)\) |
| 7 | Group Anagrams | Canonical hash key | \(O(nk\log k)\) |
| 8 | Top K Frequent Words | Map + heap | \(O(n + u\log k)\) |
| 9 | Maximum Subarray | Kadane / DP | \(O(n)\) |
| 10 | Product Except Self | Prefix + suffix | \(O(n)\) |
| 11 | Search Rotated Array | Modified binary search | \(O(\log n)\) |
| 12 | Reverse Linked List | Pointer rewiring | \(O(n)\) |
| 13 | Linked-List Cycle | Fast/slow pointers | \(O(n)\) |
| 14 | Merge Sorted Lists | Two pointers + sentinel | \(O(n+m)\) |
| 15 | Level-Order Traversal | BFS queue | \(O(n)\) |
| 16 | Validate BST | Recursive bounds | \(O(n)\) |
| 17 | Lowest Common Ancestor | Recursive aggregation | \(O(n)\) |
| 18 | Number of Islands | Grid BFS/DFS | \(O(rc)\) |
| 19 | Course Schedule | Topological sort | \(O(V+E)\) |
| 20 | Coin Change | 1-D dynamic programming | \(O(ac)\) |
Here, \(n\) is input size, \(k\) is a word length or requested result size as stated in its chapter, \(u\) is the number of unique words, \(r\times c\) is grid size, \(V/E\) are graph vertices/edges, and \(a/c\) are amount and number of coin types.
Conventions
The runnable examples deliberately use small, interview-friendly subsets of Java, Python, and Rust. Solution code uses only standard libraries; Java’s bundled JUnit 4 jars are used solely for tests, Python uses unittest, and Rust uses its built-in test framework through Cargo. See Running the examples for installation and execution instructions. Unless a problem says otherwise, assume inputs meet the stated contract. In an interview, say that assumption aloud.
The solutions favor clarity over premature optimization. A chapter’s “If the interviewer pushes” section identifies the next refinement without burdening the first implementation.
Running and publishing
Install the language toolchains described in Running the examples. From book/src, run one complete language suite:
./java/run.sh all./python/run.sh all./rust/run.sh allEach chapter provides the corresponding single-example commands in its language tabs.
From book, preview or render the Quarto book:
quarto preview
quarto renderThe left navigation and page table of contents are generated from _quarto.yml by Quarto. The final appendix supplies a cross-format manual subject index.
License
GNU General Public License v3.0 applies to the text, program source code, and Quarto source.
About the Book
This was made as a personal resource for a coding interview I need to do. After making it I thought others might be interested. If you find it helpful, let me know at adam@adamfeuer.com.
If you are interested in another language beyond Java, Python, and Rust, let me know.
This book is made in Quarto publishing system and was created with the assistance of ChatGPT.
The source code is available on GitHub at: https://github.com/adamfeuer/top-software-engineering-interview-problems
Adam Feuer