đ ď¸ How to Solve and Test
Every problem is a program that reads standard input and writes standard output. That makes them work in any language, and lets one set of test files check every solution.
The workflow
- Create a folder for your solutions anywhere (for example
solutions/java/). - Write the program. Read the whole input from stdin; print only what the problem asks for â no prompts like
"Enter n:". - Try it on an example by hand:
python3 e01.py < tests/E01/01.in(any test file works). - Run every test at once with the runner (below), or paste your output into the checker on the problem page.
The test runner
Two equivalent runners live in runner/; use whichever you have installed (Python 3.8+ or Node 18+). Run them from the problems folder and put the command that runs your program after --:
| Language | Command |
|---|---|
| Python | python3 runner/run-tests.py E01 -- python3 e01.py |
| JavaScript | node runner/run-tests.mjs E01 -- node e01.mjs |
| Java | javac Main.java then python3 runner/run-tests.py E01 -- java Main |
| C++ | g++ -std=c++17 -O2 e01.cpp -o e01 then python3 runner/run-tests.py E01 -- ./e01 |
| Anything else | Any command works: -- ruby e01.rb, -- dotnet run, -- go run e01.go, -- ./target/release/e01 |
Options: --timeout 5 (seconds per test, default 10) and --stop (stop at the first failure). A failing test shows the first line that differs:
The runner's exit code is 0 only when every test passes, so it also works in scripts and CI. Hard problems include large tests: an O(n²) solution may hit the time limit where O(n log n) is expected.
Input/output templates
Each template solves the same demo task (it isn't one of the problems), so you can see how reading and printing work in your language:
n, the second holds n integers. Print the numbers doubled on one line, then count n.
Input 3â4 -1 10 â output 8 -2 20âcount 3.Reading line by line
Most problems can be read as a stream of tokens. Read whole lines when a line may contain spaces or be empty (e.g. M01 Balanced Brackets, E04 Reverse a String, O13 Text Editor): in Python sys.stdin.read().split("\n"), in JavaScript readFileSync(0, 'utf8').split('\n'), in Java in.readLine(), in C++ getline(cin, line) (after cin >> q, skip the rest of that line first with cin.ignore()).
The OOP command loop
Every object-oriented problem has the same driver: read q, then for each command line, split it into words and call a method on your objects. Keep the driver thin: the classes do the work and return results; the driver only parses and prints.
ADD name amount (no output) and SHOW name â name total, or ERROR unknown name.
Input 3âADD ana 5âSHOW anaâSHOW bob â output ana 5âERROR unknown name.Common pitfalls
- Integer overflow. Constraints tell you when results exceed 32 bits â use
long/long long/BigInt. Python integers never overflow. - Integer division. E01 and the calculators use division that truncates toward zero, like Java and C++. Python's
//and JavaScript'sMath.floorround toward ââ instead. - Floating point. When a problem prints decimals it says exactly how (e.g. two decimals). Money problems use whole cents â never floats.
- Tie-break rules. Many problems define which answer to print when several are valid (âsmallest index firstâ, âlexicographically smallestâ). Read them carefully â they're part of the problem.
- Slow I/O. For 105+ numbers, use the fast patterns above (buffered reading, one big print).
- Extra output. Debug prints break the comparison: send them to stderr (
print(..., file=sys.stderr),console.error,System.err,cerr) â the runner ignores stderr.
A suggested path
- New to the language: E01âE25 in order â they cover I/O, loops, strings, lists and maps.
- Then M01âM25: stacks, hashing, two pointers, sorting with custom orders, recursion.
- H01âH25 are classic interview-level algorithms; aim for the complexity the constraints imply.
- For Java, C++, C#, Kotlin, TypeScriptâŚ: do O01âO25 to practise classes, interfaces, inheritance, generics and design patterns. Solve each one twice: once quickly, then refactor the design.