Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Written by Prashant Basnet
<section class="bg-white dark:bg-gray-900 px-4 py-8 max-w-2xl mx-auto text-gray-800 dark:text-gray-200">
<h1 class="text-2xl sm:text-3xl font-signature italic font-semibold text-center mb-4">
👋 Welcome — You’ve Landed on My Signature Page
</h1>
<p class="text-base sm:text-lg mb-4">
Hey, I’m <strong class="text-black dark:text-white">Prashant Basnet</strong> — software developmemt engineer at
<a href="https://unisala.com" class="text-indigo-600 dark:text-indigo-400 underline hover:no-underline" target="_blank" rel="noopener noreferrer">
Unisala.com
</a>.
</p>
<p class="text-base sm:text-lg mb-6">
You’re viewing my <strong>Signature</strong>, a digital space where I share what I’m learning, building, and reflecting on, all in one place.
</p>
<div class="border-l-4 border-indigo-400 dark:border-indigo-500 pl-4 italic mb-6 text-sm sm:text-base text-gray-700 dark:text-gray-400">
📍 Found this page via LinkedIn, my personal site, or a shared link?
<br />
This isn’t a traditional portfolio. It’s my public digital notebook where I document useful ideas, experiments, and lessons I’ve learned as I build.
</div>
<h2 class="text-lg font-semibold mb-2">What You’ll Find Here:</h2>
<ul class="list-disc list-inside space-y-1 text-sm sm:text-base">
<li>✍️ Thoughts on algorithms, systems, and software design</li>
<li>🧠 Insights from building at Unisala</li>
<li>🔗 Direct links to everything I’ve published on Unisala</li>
</ul>
</section>
Arrays are where we start as devs. But what if I told you arrays secretly stack superpowers?
1. Arrays: Where It All Begins
Arrays are simple ordered lists, but processing them often leads to O(n²) nested loops.
Brute Force: For every element, scan right until you find a larger one → O(n²).
2. Stacks: The First Power-Up 🧙♂️
When we stack books like:
Core ops:
Stacks are simple. Stacks are just LIFO structures. But it can be more than that:
3. Monotonic Stacks: Sorted Stack
Think of organising nested bowls in your kitchen. Each new bowl must fit inside the previous one.
🔹 Use case: Next Smaller Element
💡 We pop until the current element is smaller than the top, then push.
Imagine people lining up for a photo, but there’s a rule:
🔹 Use case: Next Greater Element
💡 We pop until the stack top is larger than the incoming celeb, then push.
Types:
📈 Increasing stack (bottom→top): [1, 3, 5] → used for next smaller
📉 Decreasing stack: [7, 4, 2] → used for next greater
Stacks are powerful — they solve "next greater/smaller" problems in O(n).
But they have one blind spot:
⛔ They can’t adapt to moving windows or dynamic ranges.
⚠️ Why?
4. 📦 Queue (FIFO): First-In-First-Out
Think of people lining up to buy coffee:
Core ops:
📌 Use Case: Breadth-First Search (BFS), scheduling tasks, stream processing
5. Deque (Double-Ended Queue 🚪)
Now imagine a line where people can enter or exit from either end like a room with two doors.
That’s a deque:
You can maintain ordered windows of elements, dynamically adding/removing from both ends.
6 . Deque + Monotonicity
Building deque logic is the same as stack. In both, you maintain monotonic order by popping elements that violate the desired pattern.
Stacks are amazing when working with static arrays.
A deque lets you:
You Unlock a Power Weapon of data structure.
A simple analogy imagine you’re watching a group of influencers trying to stay trending on a live ranking board that updates every minute.
a. Sliding Window Max/Min in O(n)
b. Live Range Queries: Perfect for real-time analytics like:
c. Optimized Greedy & DP: Enables efficient subarray calculations like:
Leetcode Question:
🧱 Regular Stack Problems (LIFO)
📈 Monotonic Increasing Stack Problems
📉 Monotonic Decreasing Stack Problems
🚪 Monotonic Deque + Sliding Window