Skip to content

Contact

Mexico City, Mexico
Available for remote and on-site projects.

Professional networks

LinkedIn · GitHub · Email
Applied engineering, measurable results.

How to prepare for a programming hackathon

· 4 min read · Samuel Torres

By Samuel Torres — Software & Cloud Engineer. 23+ production sites.

On November 21, 2026 I took the Google Core Hackathon End of Year on HackerRank: 4 algorithm problems in 150 minutes. The entry window ran from 10:00 to 10:30; I got in around 10:21 and finished close to 12:50. Official results take at least a week, so this post isn't about how I did. It's about what I'd change to show up better prepared, and what did work.

The main idea: preparing doesn't mean learning everything. It means practicing what comes up most, in the language you know best, under the same conditions as the contest. If you want to see how my other contests went, they're under hackathons.

1. Pick one language and stick with it

In this contest I started in C and switched to PHP. PHP is what I use every day for WordPress and plugins, and it's the language I think in. Python is faster to type, but with a clock running the shortest language doesn't win. The one that doesn't make you translate in your head does.

In practice:

  • Decide before the contest, not during it. Every minute spent switching languages is a minute not spent solving.
  • Know the functions these problems lean on. In PHP, for me that's sort(), usort() with strcmp(), explode(), array_multisort() and SplMinHeap. All but the last one came up that day; SplMinHeap is what the fast version of Minimum Health called for.
  • Know how to read input and print output. It sounds basic, but if you have to look it up mid-contest, you've already lost time.

2. Practice patterns, not problems

The 10 most common patterns and a sample practice week
The 10 most common patterns and a sample practice week

You won't get the exact problem you practiced. You'll get one that looks like it. That's why it pays to practice the pattern instead of memorizing solutions.

These are the 10 patterns that show up most in this kind of contest. Master ten patterns and you'll recognize hundreds of problems:

  1. Two pointers: two indexes moving across an array, usually sorted, to find pairs without comparing everything to everything.
  2. Sliding window: a window that slides over the array, adding what comes in and subtracting what goes out.
  3. Hashmap: count or look something up in constant time with an associative array.
  4. Stack: keep what's pending and pop the last thing pushed (brackets, next greater element).
  5. BFS/DFS: walk a graph or a grid level by level or depth first.
  6. Heap: keep the K largest or smallest without re-sorting everything each time.
  7. Binary search: halve the range at every step, over an array or over the answer itself.
  8. Sorting/greedy: sort first, then make the best local choice.
  9. 1D DP: store the best answer up to each point in a table and build the next one from the previous ones.
  10. Prefix sums: running totals so the sum of any range is a single subtraction.

Three of them showed up in my contest. Closest Numbers was sort and compare only neighbors. Ancestral Names was sorting with a custom comparison. Minimum Health, in its fast version, was a heap. Maximum Earnings was DP. None of them was new as a pattern; what was new was the disguise.

Here's the sort-and-compare-neighbors pattern in PHP, in two passes: one to find the minimum difference and one to print the pairs that have it.

<?php
function closestNumbers(array $numbers): void {
    sort($numbers);
    $n = count($numbers);
    $min = PHP_INT_MAX;
    for ($i = 1; $i < $n; $i++) {
        $min = min($min, $numbers[$i] - $numbers[$i - 1]);
    }
    for ($i = 1; $i < $n; $i++) {
        if ($numbers[$i] - $numbers[$i - 1] == $min) {
            echo $numbers[$i - 1] . " " . $numbers[$i] . "\n";
        }
    }
}

Why the pattern matters and not just "it works": with bubble sort, 100,000 numbers means about 5 billion comparisons. The math is n²/2: 100,000 × 100,000 = 10 billion, divided by 2. That won't finish in time. With sort() and a single pass over the neighbors, it will. Read the constraints before you write any code; I go deeper on that in first steps before writing a line of code.

3. Write without autocomplete

At work I code with my editor, my extensions and my shortcuts. In a contest you type into a browser editor, and the code has to run on the first try, or close to it. That's where the mistakes your editor normally catches before you even notice them come out.

After the contest I put together a list of one-character mistakes:

MistakeWrittenCorrect
Missing $numbers[$i]$numbers[$i]
Letter o instead of zero$pa[o]$pa[0]
Comma instead of semicolon$k < $n, $k++$k < $n; $k++
Assigning instead of comparingif ($diff = $min)if ($diff == $min)
Flipped sign+-+=
One brace too many or too few}—
Typo in a keyword or functionretunr, usorreturn, usort

The o one cost me. On Ancestral Names, one attempt passed only 1 of 10 test cases because I typed $pa[o] instead of $pa[0]. The one case that passed had identical names, so it never reached that line. The code "worked" on exactly the case that didn't test it.

How to practice it: solve problems in a plain editor with no autocomplete or suggestions, and run the code yourself. Every time you slip, add it to your own list. That list is gold when you review.

4. Run a mock contest

Solving a problem with no clock and solving it with 150 minutes for four are different things. The clock changes your decisions: when to drop a problem, when to settle for a slow solution that passes some cases, when to submit.

A real mock contest has:

  • The same time and the same number of problems as the real one. If it's 4 in 150 minutes, it's 4 in 150 minutes.
  • The same platform, or something close, so the editor and the input format don't surprise you.
  • No breaks. No "I'll finish this later".
  • A review at the end: which pattern each problem was, where the time went and which one-character mistake you made.

The platform also teaches you to read results. On Minimum Health I had a correct version that passed 11 of 15 cases. The 4 that failed didn't have a wrong answer: they had the clock icon, which means they ran out of execution time. If you can't tell those apart, you can spend half an hour hunting a bug that isn't there instead of making the code faster.

If the clock gets to you, that's what staying calm when the clock is running is about.

5. Read the problem statement in English

Problems come in English, and the words that decide the solution are few but important: at most, at least, distinct, ascending, non-decreasing, lexicographically, modulo. Miss one and you solve a different problem.

What helps me:

  • Read the whole statement twice before writing anything.
  • Practice with English statements even if it's slower. On contest day there's no translation.
  • Check the output format. Output is compared exactly, spaces and line breaks included.

A sample week

You don't need to study ten hours a day. You need consistency and practice under contest conditions. A sample week:

DayWhat you doWhy
MondayPatterns: 2 per day, one problem eachRecognize the pattern when it shows up in disguise
WednesdayTimed mock contest, same rules as the real onePractice decisions under time pressure
FridayReview your list of one-character mistakesDon't lose a test case to something you fix in a second

At 2 patterns per session, five sessions cover all 10. When you finish the list, start over with different problems for the same patterns.

This plan is my own advice, not a recipe backed by numbers. Adjust it to your schedule; the one thing I wouldn't drop is the timed mock contest.

What I wouldn't do

  • I wouldn't switch languages the week of the contest because I read another one is "better for competing". You'll show up less fluent at everything.
  • I wouldn't memorize solutions. The contest problem is never exactly the one you practiced.
  • I wouldn't practice only in my IDE. It won't be there on contest day.
  • I wouldn't trust that one passing case means the code is right. Mine passed one with an o instead of a zero.
  • I wouldn't get stuck on the hardest problem. Lock in what you can solve first; that's the point of do the easy one first, then level up.

Want to talk?

This kind of practice is the same thing I do at work: understand the problem, pick the tool, test before shipping. If you have a website, a plugin or a server that needs someone who works that way, get in touch through contact.

Sources

  • Contest details (4 problems, 150 minutes, entry window, times, per-problem results, the $pa[o] case, the Minimum Health timeouts, the switch from C to PHP): Samuel's own experience at the Google Core Hackathon End of Year (HackerRank, Nov 21, 2026).
  • The 10 patterns, the 5 points and the sample week: Samuel's own advice, not backed by a study.
  • Bubble sort comparison count (n²/2 with n = 100,000): own calculation, explained in the text.
  • sort() — php.net
  • usort() — php.net
  • strcmp() — php.net
  • explode() — php.net
  • array_multisort() — php.net
  • SplMinHeap — php.net

About the author

Samuel Torres is a Software & Cloud Engineer at Conqr Digital Agency (Mexico City). He runs 23+ production WordPress sites and processed 80,000 documents with OCR + LLM. More at /en/about. Get a quote on WhatsApp in 2 min

Samuel Torres Pichardo

Samuel Torres Pichardo
Software and cloud engineer in Mexico City, with about 3 years of professional experience.
About me · LinkedIn · GitHub · Contact

Got a project in mind?

Hire me: I'll help you build it.

Websites, online stores, custom systems and cloud. Tell me what you need and I'll tell you how I'd build it, what it costs and how long it takes.

  • Mexico City · remote

Menu

Español

[email protected]