This Problem Looked Easy — Until I Let It Break Me (LeetCode 310)

Ishan DixitIshan Dixit
3 min read

It wasn’t a trick I needed. It was a new system.


🧩 Introduction: The Mask of Simplicity

I’ve attempted LeetCode 310 — Minimum Height Trees — before.
Tried to break it down. Even thought I had it at one point.

But I never submitted it.
I marked it red in my personal sheet —
“Redo” in my notebook, because I knew I hadn’t cracked it.

It wasn’t just unsolved — it was unearned.
And this time, I didn’t want a pass.
I wanted a system.


🌪️ The Loop of Confusion

People say:

“Remove leaves, repeat until 1 or 2 nodes remain. That’s your root.”

Sounds easy, right?
So why was I stuck re-reading my code?
Why did pushing just the leaves feel so wrong, so fragile?

Because I didn’t understand why it worked.
And I refused to settle for another memorized trick.


🔍 What I Saw (Eventually)

I thought BFS.
I thought containment.
I thought, “maybe I can simulate levels from all directions.”

But every time, the logic fell apart.
Until I stopped trying to force the center…

…and let it emerge.


🌿 The Shift: From Simulation to Collapse

That’s when it clicked:
I wasn’t supposed to build anything.
I was supposed to watch things disappear.

Every node starts with a degree.
And when its neighbors get peeled off, one by one,
the last ones standing aren’t there because we built them up —
they’re there because we let everything else die.

This isn’t a construction problem.
It’s a survival problem.


🔥 The System, Not the Trick

Here’s what I learned:

  • You don’t push nodes because they’re good — you push them because they’re weak.

  • You don't try to "reach" the root — you burn everything else until it’s revealed.

  • Degree isn’t just math — it’s life force. And when it hits 1, you're watching a dying leaf.

  • Visited arrays? BFS queues? Forget them. All noise, if you don’t see the system beneath.


🧠 Code with Clarity (C++)

vector<int> findMinHeightTrees(int n, vector<vector<int>>& edges) {
    if (n == 1) return {0};

    vector<vector<int>> graph(n);
    vector<int> degree(n, 0);

    for (auto& e : edges) {
        graph[e[0]].push_back(e[1]);
        graph[e[1]].push_back(e[0]);
        degree[e[0]]++;
        degree[e[1]]++;
    }

    queue<int> q;
    for (int i = 0; i < n; ++i)
        if (degree[i] == 1)
            q.push(i);

    while (n > 2) {
        int sz = q.size();
        n -= sz;
        while (sz--) {
            int node = q.front(); q.pop();
            for (int neighbor : graph[node]) {
                if (--degree[neighbor] == 1)
                    q.push(neighbor);
            }
        }
    }

    vector<int> res;
    while (!q.empty()) {
        res.push_back(q.front()); q.pop();
    }
    return res;
}

💭 The Part I’ll Never Forget

At one point, I said to myself:

“Maybe the leaf is the answer.”

That was the shift.
Not because the leaf had the solution — but because it helped reveal who did.

Every decay, every layer peeled off, every “why isn’t this working” moment…

It was never wasted.
It was building my own system, one wrong intuition at a time.


🎤 If You’re Still Stuck

You’re not dumb.
You’re not slow.
You’re just peeling a problem that doesn’t like to scream its truth loudly.

Let it rot.
Let it fall apart.
And trust: the root always survives.


Written by someone who solved this problem twice —
once on LeetCode, and once inside their head.

0
Subscribe to my newsletter

Read articles from Ishan Dixit directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ishan Dixit
Ishan Dixit