I studied data structures and algorithms for the same reason most people do: to get a job.
Grind Leetcode. Pass the screen. Look sharp on paper. That was the plan. What I didn't expect was that the knowledge would reach back nearly a decade and rewrite history on a problem I thought I had put to bed.
The problem I was solving
Almost a decade ago, I was working as an analytics engineer in oil and gas. An engineer on the team had been struggling with a problem in Tableau for weeks. He couldn't crack it. It landed on my desk.
The job was to detect aggressive cycling in a live pipeline. Products moved under pressure, and the engineers needed to know when that pressure was swinging violently between highs and lows. They had a formal framework for this: rainflow counting, a fatigue analysis method developed by Japanese researchers Tatsuo Endo and M. Matsuishi in 1968. The core idea was to convert a chaotic pressure history into identifiable stress cycles, then flag the ones violent enough to cause damage. A stream of sensor readings arriving in real time looked something like this:
Pressure climbs to 2,744 PSI, then collapses to 892. Climbs again to 2,901, then craters to 567. Two cycles. Both violent. Both worth flagging. My job was to catch those turning points as the numbers arrived, calculate the swing between each peak and valley, and fire an alert when the amplitude crossed the engineers' threshold. Simple enough to describe. A nightmare to build.
Why the first solution was messy
Tableau couldn't loop, so I pushed the logic down to the data layer. The team had Alteryx; a drag-and-drop workflow tool, powerful for what it was designed for, and not designed for this. What I built worked. But I can only describe it as a creature stitched together in real time: nodes feeding into nodes, branches compensating for gaps, logic layered on top of logic until it stood upright through sheer stubbornness. I had built something real. I just had no idea what I was standing on.
- Many nodes and branches
- Logic layered on logic
- Difficult to change
- Hidden complexity
- Single pass over data
- Clear mathematical logic
- Reusable thinking
- Easier maintenance
Every change request sent a spike of dread through me, and it had nothing to do with the work. I didn't trust what I had built. I was soldering wires while the machine was running, praying nothing shorted.
The deeper problem wasn't Alteryx. It was how I had approached the problem. I started building before I truly understood what I was solving. I never stopped to ask whether the problem had a name, whether someone had already solved it, whether there was a body of knowledge I was supposed to be standing on.
There was. I just didn't know it yet.
The pattern I missed
Years later, on a different job, I started studying data structures and algorithms. Still mostly to pass interviews. I was working through a pattern called the sliding window, a technique for tracking a moving subset of data as you process a sequence. It gave me a mental model I had never had before: how to reason about a stream of values as a living, moving thing rather than a static dataset to be queried.
That idea led me to another pattern: the monotonic stack.
The monotonic stack connection
A structure that maintains order as values arrive in a stream, holding them until the moment the trend breaks. Then it reveals something simple but powerful: a peak or a valley. In a single pass, it reduces chaos into structure.
I was working through an example when something shifted. I put the book down.
The sensor readings. The peaks. The valleys. The same logic I had once stitched together in Alteryx, except now expressed cleanly, mathematically, almost trivially.
Peak detected, flag it. Valley detected, flag it. Measure the swing. Compare it to the threshold. Trigger the alert.
The entire system I had spent weeks building was sitting there, reduced to its mathematical skeleton.
It was the same idea I had already been wrestling with in a more complicated form: tracking turning points in a stream of data as the trend shifts between rising and falling.
Here is what it looks like in Python in less than 10 lines. Clean, readable, fast. The kind of code you can hand to someone else without a thirty minute explanation and a prayer.
def detect_turning_points(readings, threshold): peaks, valleys = [], [] for i in range(1, len(readings) - 1): if readings[i] > readings[i-1] and readings[i] > readings[i+1]: peaks.append((i, readings[i])) elif readings[i] < readings[i-1] and readings[i] < readings[i+1]: valleys.append((i, readings[i])) return [(p, v) for p in peaks for v in valleys if abs(p[1] - v[1]) >= threshold]
What changed in how I think
Three things became clear.
I call this standing on the shoulders of others. It sounds humble. It is. But it is also the most efficient thing a problem solver can do.
DSA sharpened my resume. It sharpened my interviews. What I didn't expect was that it would sharpen how I think.