← Writing

How Competitive Programming Shaped How I Code

Years of algorithmic contests left habits that still show up in how I approach engineering problems today.

At my first serious contest I submitted the wrong answer three times on a problem I understood. I just hadn't read the constraints. After that, I started sitting with problems before touching the keyboard.

Think before you type

In a contest, you have limited submissions. Wrong answers cost time. So you develop a habit of sitting with a problem, finding the edge cases, mentally running through examples before writing a single line.

Most professional engineers do the opposite. They open a file and start typing. The code becomes the thinking. This isn't always wrong — sometimes you need to explore — but I find that most bugs I've seen in production come from code written before the problem was understood.

The contest reflex: read the problem twice, find the constraints, ask what happens at n=0, n=1, n=max.

Complexity is a first-class concern

When you've trained to spot an O(n²) loop that will TLE on n=10⁵, you start seeing it everywhere. In production code, in API designs, in database queries that looked fine on 100 rows but crawled on 100,000.

This isn't premature optimization. It's noticing when something will be wrong before it's wrong.

The value of clean solutions

Competitive programming teaches you that most problems have a shape, and if you find it, the solution follows naturally. A brute-force approach exists for many problems — sometimes it clears the time limit, sometimes it doesn't, and sometimes it's just too tedious to implement correctly under pressure. Either way, it's a dead end. When you sit with a problem and think from first principles, you often find something smaller and more direct: not shorter for its own sake, but simpler because it's working with the structure of the problem instead of around it.

In professional settings, I've watched engineers build elaborate state machines to solve problems that had clean recursive solutions. The elaborate version was tested and code-reviewed and still had a bug in a state transition. The clean version would have been obviously correct — not because it was concise, but because it mapped directly to the structure of the problem.

What competitive programming doesn't teach

It's worth naming the gaps.

Contests have no users, no maintainability concerns, no performance at scale beyond the test cases given. Code that wins a contest would be a nightmare to maintain. Variable names like dp[i][j] are fine when you're the only reader; they're not fine when you're onboarding a new engineer.

It also doesn't teach you to work with other people's code — which is most of what professional engineering is.

The lasting reflex

The thing that stuck most isn't any specific technique. It's the habit of asking: what's the shape of this problem? Before writing code, before opening a file — what are we actually solving, and what does a clean solution look like?

That question, more than any algorithm, is what competitive programming taught me.