
By Samuel Torres — Software & Cloud Engineer. 23+ production sites.
On November 21, 2026 I took part in 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 around 12:50. Official results take at least a week, so there's no final ranking or prize in this post. What I can share is what I saw on my side: Closest Numbers solved, Ancestral Names passing every case, Minimum Health at 11 of 15 cases, and Maximum Earnings submitted in the last few minutes without a confirmed result.
Of everything I took away from that day, this is the lesson I'll use first next time: in a timed challenge, you earn points by locking in the safe ones first, not by charging at the hardest problem. A hard problem half-solved is worth the same as one you never opened. An easy problem at 11 of 15 cases already counts.
Read all 4 problems before you write anything
The easiest mistake is opening the first problem and starting to type. It feels productive, but you have no idea whether problem 3 was the easiest one on the test.
Here's what I'd do in the next challenge: a 2-minute scan.
- Read all 4 statements: just the title, the idea and the sample. Don't dig into the constraints yet.
- Mark the one that looks most approachable. The one you get on the first read, the one that looks like something you've done before, the one whose sample you can solve by hand.
- Estimate how long each one would take, even roughly: 20 minutes, 40 minutes, "no idea where to start."
- Pick an order and write it on paper. That piece of paper is your plan once the clock starts squeezing.
Two minutes out of 150 is just over 1% of the time (2 ÷ 150 = 0.013). In exchange, you know from the start where the cheapest points are.
One warning: the scan isn't for solving anything. If you catch yourself thinking about the code for problem 3 while reading problem 4, jot it down in one line and keep reading. I go into how to read a statement properly in first steps before writing a line of code.
My real call: Minimum Health

I had less than an hour on the clock and two problems left: Minimum Health and Maximum Earnings. Maximum Earnings called for dynamic programming; Minimum Health looked simpler. I went for the simpler one.
The idea of the problem: at each level a new player arrives with a strength value. Charlie fights the player sitting at position rank among the strongest, and you keep adding up the strength of each opponent. "Position rank among the strongest" is the same as sorting the list and picking an index, something I had already done twice that same day in the earlier problems.
I'm not going to reproduce HackerRank's exact input format here. What matters is the logic, so I'll write it as a function that takes an array with each player's strength, in arrival order, plus rank.
First, the version that works
<?php
function rivalesLento(array $fuerzas, int $rank): int
{
$lista = [];
$total = 0;
foreach ($fuerzas as $f) {
$lista[] = $f;
sort($lista);
if (count($lista) >= $rank) {
$total += $lista[count($lista) - $rank];
}
}
return $total;
}
Add the new player, sort ascending with sort(), and take $lista[count($lista) - $rank]. With 5 players and rank 2, the second strongest sits at index 5 − 2 = 3, the second to last. The if covers the first levels, before there are rank players; depending on the real statement that may never happen, but guarding it costs nothing.
A hand-worked example with strengths [5, 1, 8, 3, 9] and rank = 2:
| Arrives | Sorted list | Opponent (2nd strongest) | Total |
|---|---|---|---|
| 5 | 5 | fewer than 2 yet | 0 |
| 1 | 1, 5 | 1 | 1 |
| 8 | 1, 5, 8 | 5 | 6 |
| 3 | 1, 3, 5, 8 | 5 | 11 |
| 9 | 1, 3, 5, 8, 9 | 8 | 19 |
This version is correct. It locked in 11 of 15 cases for me. The 4 that failed showed a clock icon, and it's worth reading that right: a clock on a test case means the run hit the time limit (a timeout), not that the answer was wrong. The logic was fine; speed was the problem.
Why it's slow
At every level I sort the whole list again, even though only one player arrived. With n players that's n sorts, each one bigger than the last. On small inputs you don't notice; on the big cases, the clock wins.
Then, the fast version
The fast version uses SplMinHeap, a structure that ships with PHP and always keeps the smallest value on top. The trick: the heap holds **only the rank strongest players**. The weakest of that group is exactly the one at position rank, and that's what top() returns.
<?php
function rivalesRapido(array $fuerzas, int $rank): int
{
$heap = new SplMinHeap();
$total = 0;
foreach ($fuerzas as $f) {
$heap->insert($f);
if (count($heap) > $rank) {
$heap->extract();
}
if (count($heap) === $rank) {
$total += $heap->top();
}
}
return $total;
}
Step by step: push the new player with insert(). If the heap now holds more than rank players, pop the weakest with extract(); that player can never be an opponent again, because there are rank stronger ones. Whatever is left at top() is this level's opponent. With the same example, [5, 1, 8, 3, 9] and rank = 2, it returns 19, same as the slow version.
The difference: nothing gets sorted anymore. Each insert() or extract() works on a heap that never grows past rank + 1 items, instead of re-sorting a list that gets longer every level.
During the challenge, this version stayed an optional upgrade: I had 11 cases locked in and another problem still unsolved, so I moved on to Maximum Earnings. I submitted that one in the last few minutes and didn't get to confirm the result.
Make it work, then make it fast
This isn't just about Minimum Health. Closest Numbers went a similar way: my first idea was a bubble sort, and with n = 100,000 values that's about 5 billion comparisons (n²/2 = 100,000 × 100,000 ÷ 2 = 5 × 10⁹). A guaranteed timeout. I swapped it for PHP's built-in sort(), and the problem became "sort, then compare only neighbors."
The rule I'm keeping:
- A slow, correct solution already scores. The small cases pass even when the big ones don't.
- A fast, wrong solution scores nothing. And it's harder to debug, because you don't know whether the bug lives in the idea or in the optimization.
- The slow version doubles as your test. When you write the fast one, run both on the same input. If they disagree, the bug is in the new one.
Break the big problem into small ones
When a problem looks huge, it's almost always three or four small problems glued together. Minimum Health splits like this:
- Store players as they arrive.
- Find the one at position
rankamong the strongest. - Add their strength to the total.
Step 2 is the only hard part, and you can solve it the dumbest way first (sort everything) and improve it later without touching steps 1 and 3. That's exactly what the heap version does: it only swaps out step 2.
Ancestral Names worked the same way: split the name from the Roman numeral with explode(), convert the numeral to a number, and sort with usort(). Three pieces, each one testable on its own. More on reusing those pieces in use what you already learned.
Save before you take a risk
Before you touch a version that already passes cases, save it. Submit it, copy it to a separate file, or leave it commented out below. Whatever works, as long as there's a copy you know is good.
The reason is simple: optimizing under the clock is exactly when one-character bugs slip in. A missing $, a comma instead of a semicolon, an = where you meant ==. If the new version breaks and the old one is gone, you can lose in five minutes what took you half an hour. If you kept the copy, you roll back and nothing happened.
When the clock is tight and the screen fills up with red, it also helps to have a method for not panicking; I cover that in staying calm when the clock is running.
What I wouldn't do
- I wouldn't start with the hardest-looking problem "to get it out of the way." If you get stuck there, you burn the time meant for the easy ones.
- I wouldn't write the optimized version first unless it's already clear in my head. Working version first.
- I wouldn't read the clock icon as "wrong answer." If the logic holds and you only need speed, don't rewrite the idea: change the data structure.
- I wouldn't overwrite the only version that passes cases. Save first.
- I wouldn't stay glued to one problem until time runs out while another one is still untouched. Lock in what you have and move up to the next one.
Want to talk?
If you have a project that needs this way of working (lock in what works first, then optimize), reach out on the contact page. And if you're into coding challenges, hackathons has what I've written about them.
Sources
- Challenge format, timing, the call to go for Minimum Health, 11 of 15 cases with the slow version, the clock icon meaning timeout, Maximum Earnings submitted without a confirmed result: Samuel's own experience at the Google Core Hackathon End of Year (HackerRank, Nov 21, 2026).
- Bubble sort with n = 100,000: about 5 billion comparisons (own calculation, n²/2, explained in the text).
sort()— php.netusort()— php.netexplode()— php.netSplMinHeap— 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



