logo

kamal's Blog

🤟 Welcome to my tech blog. 💻

About Me

Hey there, I’m Kamal! 🤘 A tech enthusiast with a knack for sharing my mostly silly (and occasionally brilliant 🤯) discoveries in the coding world. This blog is my playground, where I spill the beans on what I’m learning—whether it’s the basics, the latest tech, or random tidbits that might make you go, “Wait, that’s a thing?” 😅

Here, you’ll find a mix of flexing, cheeky jokes, and even the occasional “mokka” humor to keep things real. Coding is fun, and I write these posts with that same energy! So if you’re having a rough day, stop by—you’ll either walk away grinning or at least wondering, “What was that?!” 😜

Stick around, laugh a little, learn a lot, and remember: coding is fun, and so is reading about it here! 🎉

Stack Sorcery: NSE, NGE, PGE & PSEE Explained With Drama 🔥🧠

🧠 Stack Operations That Made Me Feel Like a Genius (After Feeling Like a Fool First) 🤦‍♂️➡️😎

NSE, PSEE, NGE, PGE — The Four Horsemen of Stack Glory 🐎🔥

Alright folks, gather around. Today we are diving into the legendary world of stacks — a place where logic lives, errors haunt, and your self-confidence gets punched and hugged at the same time.

This is the story of how NSE, NGE, PSEE, PGE almost turned me into a motivational speaker… out of pain…
but then lifted me like Rajinikanth’s slow-motion entry. 😎🔥

Let’s begin.


🤝 The Beginning: Me vs Stack

When I first heard words like Next Smaller Element, Previous Greater Element, I legit thought:

“Bro, why are we comparing exes here? Just let the past go da.” 😭

But no.
Turns out it’s just DSA… but with attitude.

I entered that chapter like a hero…
and got slapped by stack operations within 5 minutes.
But don’t worry — now I’m the one slapping back. 💥


🔥 1. NGE – Next Greater Element

Meaning:
For every element in the array, find the next element on the right that is greater than it.

In simple language:
“Who is the next guy that flexes more than me?” 😎

How we fail initially:
We loop from left → right
We compare every element with every other
We get TLE faster than you can say “Leetcode123”.

How stack saves us:
We go from right → left,
use a stack to keep only the “useful heroes”,
and discard all the weaklings on the way.

Harvey Specter explanation:
“Win a case before it even starts. Remove unnecessary people before they waste your time.”
That’s exactly what stack does. ✨


❄️ 2. NSE – Next Smaller Element

Meaning:
Find the next element on the right that is smaller.

AKA:
“Who is the next guy shorter than me?” 😌

Approach is the exact sibling of NGE.
Just instead of greater → look for smaller.

And the cool part?
When you understand NGE properly,
NSE feels like copying homework and just changing names. 😭🔥


⏳ 3. PGE – Previous Greater Element

Meaning:
Look LEFT and find the element that is greater than the current one.

It’s literally NGE… but the camera turned 180 degrees. 📸

And bro…
first time I learned this I was like:

“Array la pakkathula irukura number ah patha podhuma? Why reverse, why stack, why stress??”

Then stack said:
“Because I’m efficient, da.” 😎


🕯️ 4. PSEE – Previous Smaller or Equal Element

This one…
this is where my brain did a somersault.

Meaning:
Find the element on the LEFT that is smaller or equal.

The first time I read that “or equal”…
my brain:
“Ayoo extra condition ah? Already confuse pannitinga.” 😭

But guess what?
Same stack principle.
Same “pop until condition satisfies”.
Same feeling of confidence when it finally works.


🧩 The Common Pattern (Your Aha Moment!)

If you understand this one paragraph,
you’ve mastered all 4 problems:

  • Go left → right or right → left based on which “next/previous” you need.
  • Maintain a stack of candidates.
  • While the top of the stack is not useful, pop it.
  • Whatever remains on the top = your answer.
  • Then push the current element.

Boom.
You are now the Harvey Specter of stack problems. 😎🧠🔥


🎭 How It Felt When I Finally Understood This

First 2 days:
“What the hell is this? Why so many variants??” 🤬

Day 3:
“Oh…
so everything is the SAME problem with direction changes?!” 😭💡

Day 4:
“I am unstoppable.” 😎🔥

Day 5:
“Let me teach the world.” 🧘‍♂️✨


🎉 Why You MUST Learn This

Because stack pattern appears EVERYWHERE:

  • Stock span problems 📈
  • Histogram area max 📊
  • Sliding windows
  • Monotonic stack questions
  • Leetcode 100+ problems
  • Interviews where the interviewer wants to test your brain’s pressure limits 😭

Learn this once.
Your DSA graph goes brrrr 📈🔥


📝 End Note

I know blogs have been dropping a little slow lately…
My bad da. Life is fast, but I’ll catch up. 😎✌️
But when I come back, I come back with quality.
Just like this stack masterpiece. 😂🔥


🔥 Stay sharp. Stay stacked. Stay unstoppable.