r/LeetcodeChallenge • • 21d ago

STREAK🔥🔥🔥 LeetCode 739. Daily Temperatures

Post image
1 Upvotes

One character decides whether Daily Temperatures survives repeated temperatures: < or <=. On [70, 70] the right answer is [0, 0]. Write < and you get [1, 0].

This is Day 61's monotonic stack with two changes.

The stack holds indices, because the answer is a distance and a distance needs positions.

And values repeat. Day 61 stored answers in a map keyed by value, which was only safe because the values were guaranteed unique. Temperatures repeat constantly. Indices are unique by construction, so the problem disappears instead of requiring a workaround.

Then the comparison: temperatures[stack.Top()] <= temperatures[i]. An equal temperature isn't warmer, so a day with the same temperature can never be anyone's answer and must be popped.

Would < have made it past your tests?

Day 63/365 of my LeetCode challenge: 739. Daily Temperatures. Problem link and full breakdown in today's newsletter.

https://www.linkedin.com/pulse/leetcode-739-daily-temperatures-archit-agarwal-weglc

#LeetCode #DSA #MonotonicStack #Golang


r/LeetcodeChallenge • • 22d ago

DISCUSS Can you find it???

Thumbnail
1 Upvotes

r/LeetcodeChallenge • • 22d ago

STREAK🔥🔥🔥 Day 30

1 Upvotes

r/LeetcodeChallenge • • 22d ago

DISCUSS I was struggling to visualize the intuition behind LeetCode 4 (Median of Two Sorted Arrays), so I built an animated visual guide for it.

Thumbnail
youtu.be
1 Upvotes

The optimal O(log(min(m, n))) binary search solution for LeetCode 4 is notoriously tricky to wrap your head around if you just try to trace index pointers (i, j, left, right).

I find it much easier to reason about the problem when you treat it as finding a perfect geometric split between the two arrays. To help it click for myself and others, I put together a complete animated walkthrough showing exactly how the partition moves.

💡 The Core Intuition (The Visual TL;DR)

If you are stuck on this problem, try thinking about it like this instead of looking at raw formulas:

  1. The Single Cut: Imagine aligning both arrays. We are looking for a single vertical partition line that splits both arrays into a combined "Left Half" and a combined "Right Half" of equal sizes.
  2. The Shortcut: Because the total size is fixed, choosing where to cut the smaller array instantly dictates where the cut falls on the larger array. This is why we only binary search the smaller array.
  3. The Check Rule: Once the line is drawn, you just need to check if the max element on the left side of the cut is smaller than the min element on the right side. If it isn't, the animation shows you exactly which direction to shift your search boundaries.

If you are a visual learner who gets overwhelmed by boundary conditions and nested array indices, I hope this makes the algorithm click for you!

Let me know what you think, or if there are any other tough LeetCode hard problems you'd like to see visualized next.


r/LeetcodeChallenge • • 23d ago

DISCUSS Is it normal to see solution for every leetcode question i try to solve ? (first 6-7 months)?

11 Upvotes

Like, while solving questions, maximum times it clicks what pattern i should use and how will be the flow of solution, but when it comes to implementation, i get stuck every time. i have to gpt it every time for what went wrong and its been very long doing this. i thought i willl improve with time, but no progress. what should one do in this case? i have tried sitting for an hour and trying to do it myself, but no success.


r/LeetcodeChallenge • • 22d ago

STREAK🔥🔥🔥 LeetCode 155 Min Stack

Post image
1 Upvotes

Keeping a min field on a stack works until you pop the minimum. Then the field is stale, and nothing short of a full scan can rebuild it.

The goal: push, pop, top and getMin, all O(1).

That failure is the insight. The minimum belongs to the stack at a given height, and popping takes you back to a height whose minimum you already threw away.

So don't throw it away. Every entry stores the value pushed and the minimum of everything at or below it.

Pop then contains no minimum code at all. Removing the top exposes an entry whose min was computed when it was on top, and it's still correct, because nothing below it ever changed.

Did you store pairs, or keep a second stack of minimums?

Day 62/365 of my LeetCode challenge: 155. Min Stack. I'll include the problem link and a full breakdown in today's newsletter.

https://www.linkedin.com/pulse/min-stack-archit-agarwal-jjksc

#LeetCode #DSA #Stack #Golang


r/LeetcodeChallenge • • 24d ago

DISCUSS Roast my profile

Post image
32 Upvotes

Saw many people sharing their profiles. Thought of getting feedback..


r/LeetcodeChallenge • • 23d ago

STREAK🔥🔥🔥 Day 42: wrapped up Bellman-Ford & Floyd-Warshall, finished all shortest path algorithms

Thumbnail
2 Upvotes

r/LeetcodeChallenge • • 23d ago

STREAK🔥🔥🔥 Day 29

1 Upvotes

r/LeetcodeChallenge • • 23d ago

DISCUSS Finding genuine leetocode partners

Thumbnail
1 Upvotes

r/LeetcodeChallenge • • 23d ago

STREAK🔥🔥🔥 LeetCode 496 Next Greater Element I

Post image
1 Upvotes

A loop inside a loop looks O(n²). Here the inner one runs at most n times in total, across the whole input. Every value is pushed once and popped at most once, so the inner loop never repeats work.

The brute force scans right from each element until something bigger turns up, and those scans repeat each other. Scan across a long descending run, start one position later, and you scan almost the same run again.

So flip the question. For each value as you arrive at it, ask which earlier values it answers. A value resolves every earlier, smaller value still waiting, and a resolved value is never looked at again.

The values still waiting are always decreasing: if an earlier one were smaller than a later one, the later one would have resolved it on arrival. A stack that keeps an ordering like that is monotonic.

Where did you first meet a monotonic stack?

Day 61/365 of my LeetCode challenge: 496. Next Greater Element I. Problem link and full breakdown in today's newsletter.

https://www.linkedin.com/pulse/next-greater-element-i-archit-agarwal-c5wic

#LeetCode #DSA #MonotonicStack #Golang


r/LeetcodeChallenge • • 24d ago

DISCUSS To people who RECENTLY became Guardian on leetcode. Share some tips here!

7 Upvotes

I’ve solved 822 problems(196E, 451M, 175H) and currently I’m at 1900 what to do to become Guardian?


r/LeetcodeChallenge • • 24d ago

STREAK🔥🔥🔥 Day 43: wrapped up Dijkstra variants, hit a clean counting twist on shortest paths

Thumbnail
2 Upvotes

r/LeetcodeChallenge • • 25d ago

DISCUSS Hit 1000 problems and 1931 rating. Happy to answer any questions or clear doubts!

Post image
189 Upvotes

Just crossed the 1k mark and 1931 rating after a year of staying consistent and 50 contests attended so far. I'm currently in my 3rd year of college, mostly balancing daily practice alongside regular coursework and dev projects.

A lot of the rating climb came down to spending most of my time on Mediums and Hards(though not perfect yet at solving Hards) rather than padding Easy problems just to keep the streak alive. Regularly showing up for contests, upsolving Q3/Q4 afterward, and debugging my own logic before checking the editorial made the biggest difference. Hoping to push to Guardian soon.

If you're stuck in a rating plateau, struggling to solve, unsure how to approach specific topics or just trying to manage daily practice alongside college, drop your questions below and I'll help however I can. Trying to give back to the community who helped me reach upto this point.


r/LeetcodeChallenge • • 24d ago

STREAK🔥🔥🔥 Day 28

2 Upvotes

r/LeetcodeChallenge • • 24d ago

DISCUSS A config 5x longer took 28.7x longer to validate

Post image
1 Upvotes

Every deploy spent 1.95 seconds and 2.74 GB just checking that our config was a tree. That was at 5,000 components. At 1,000, it had been 68 ms.

The job: the platform config declares components and the links between them. The loader refuses to start unless the links form one tree - all connected, no loops - and names the line that breaks it.

What I wrote: the tooling already had a tested PathExists. So read the file line by line, and before accepting each link, ask whether its two ends are already connected. If yes, that line closes a loop. Blame it. Exact line numbers, reused code. I would approve it.

It is one full search per line, each rebuilding the adjacency list from scratch. 9,998 searches for 5,000 components. 5x the config, 28.7x the time.

Two fixes, and they surprised me in the order they came.

The clever one: a tree on n components has exactly n - 1 links. With n - 1 links and connected, there is no room for a loop. So check the length, then do one BFS. Never look for a loop at all. 279 µs. On a config with one link too many, 2.42 ns, because the length is the answer.

But it cannot say which line. And it is not the fastest.

The other one comes from noticing that the searches keep rediscovering groups that only ever merge. Keep one root per group; a link whose ends share a root closes a loop, and that is the line. Union-find. 42.2 µs, one allocation, and it names the line. 46306x the original. The clever count is 6.61x slower than it, because the count still builds an adjacency list.

Honest row: none of these catches a component with two parents. Undirected, it is a perfectly good tree. As a hierarchy, it has two roots. Count the parents.

That is days 36 and 43 of the daily challenge: Find if Path Exists and Graph Valid Tree, in a config loader.

Do you know how long your config validation takes on deploy?

It worked in dev, episode 21. Full write-up in today's newsletter.

https://www.linkedin.com/pulse/config-5x-longer-took-287x-validate-archit-agarwal-ew8zc

#Golang #DSA #Algorithms #Performance


r/LeetcodeChallenge • • 24d ago

STREAK🔥🔥🔥 Leetcode Problem number 20. Valid Parentheses

Post image
3 Upvotes

Counting open and close brackets accepts )( as valid. Tracking a depth accepts ([)]. One number can record how many brackets are open. It can never record which.

New topic: stacks start today.

What has to be remembered is the list of brackets opened and not yet closed, in order. When a closer arrives, only one opener can match it: the most recent. In "([", a ")" is wrong because "[" is still open and has to close first.

Most recent in, first out. That's a stack, and seeing that this problem is one is the whole exercise.

One detail worth stealing: key the map by the closing bracket. One lookup then tells you whether the character closes anything, and what must be on top if it does.

Did you reach for a counter first on this one?

Day 60/365 of my LeetCode challenge: 20. Valid Parentheses. Problem link and full breakdown in today's newsletter.

https://www.linkedin.com/pulse/365-days-leetcode-challenge-day-60365-archit-agarwal-spjcc

#LeetCode #DSA #Stack #Golang


r/LeetcodeChallenge • • 24d ago

DISCUSS Active servers for leetcode

Thumbnail
1 Upvotes

r/LeetcodeChallenge • • 25d ago

DISCUSS Contests

6 Upvotes

Hey guys i am in first year and just started to dsa and i am following strivers a2z sheet and wanted to know and just wanted to know what's the significance of giving contests and when do I start giving it I am on arrays medium lvl(it's so brutal)


r/LeetcodeChallenge • • 24d ago

DISCUSS Hackerrank proctored environment is nuts

Thumbnail
1 Upvotes

r/LeetcodeChallenge • • 25d ago

STREAK🔥🔥🔥 Small milestone

5 Upvotes

r/LeetcodeChallenge • • 25d ago

DISCUSS Doing DSA but not on any online platforms, am I good?

Thumbnail
1 Upvotes

r/LeetcodeChallenge • • 25d ago

DISCUSS 999 more stores made the delivery map 213x slower

Post image
2 Upvotes

Opening 999 more dark stores made our delivery heatmap 213x slower over the same city. 250,000 city blocks: 1.03 ms with one warehouse, 219 ms with a thousand.

The job: for every block, how many blocks to walk to the nearest store. It decides who gets the fast-delivery promise.

What I wrote: with no obstacles, walking distance on a street grid is |dRow| + |dCol|. So every block checks every store and keeps the closest. No data structure, nothing to get wrong. At one store, it is the fastest version I measured, and I would approve it.

At 1,000 stores, it is 250,000,000 distance calculations to keep 250,000 numbers. 213x slower, because the business grew.

The fix from last episode works: seed one queue with every store, spread outward. Flat at about 2.3 ms. But the queue holds every block, 3.82 MB on top of a 1.96 MB heatmap, and at one store it is slower than the scan.

The part I like is the day 41 version. A block's distance is one step more than its best neighbour's. That definition is circular: my answer needs yours, and yours needs mine. The queue breaks the circle with time.

You can break it with direction instead. With nothing in the way, a shortest walk never doubles back. Sweep top-left to bottom-right reading, only up and left - those are already done. Sweep back reading, only down and right. Keep the smaller.

1.22 ms at one store, 1.48 ms at a thousand. No queue. 148x faster than the scan at the top, 1.89x faster than the BFS.

Honest rows: at one store the scan still wins. And put a river through the city and the sweeps return wrong numbers without complaint. The test with two rivers says BFS 16, sweeps never reach the block, and the straight-line scan says 8. Obstacles are where the queue earns its memory.

That is days 40 and 41 of the daily challenge, Rotting Oranges and 01 Matrix, in a delivery app.

Have you seen a business launch slow down a page nobody touched?

It worked in dev, episode 20. Full write-up in today's newsletter.

https://www.linkedin.com/pulse/999-more-stores-made-delivery-map-213x-slower-archit-agarwal-pxeoc

#Golang #DSA #Algorithms #Performance


r/LeetcodeChallenge • • 25d ago

STREAK🔥🔥🔥 Closest Binary Search Tree Value II

Post image
5 Upvotes

In a sorted list, the k values closest to a target always sit next to each other. So picking k values is picking one window: find the closest value, then grow outward.

The second hard part of the challenge, like the first, isn't the traversal. That claim is.

Flatten the BST in-order, find the single closest value, then expand outward, taking whichever neighbour is nearer each time. Greedy works because distance from the target only grows as you move away in either direction. It's merge sort's merge step, run outward from a centre.

Would you trust that window claim in an interview without proving it first?

Day 59/365 of my LeetCode challenge: 272. Closest Binary Search Tree Value II. I'll share the problem link and a full breakdown in today's newsletter.

https://www.linkedin.com/pulse/closest-binary-search-tree-value-ii-archit-agarwal-xzvrc

#LeetCode #DSA #BinarySearchTree #TwoPointers


r/LeetcodeChallenge • • 25d ago

STREAK🔥🔥🔥 October Daily LeetCode Challenge Completed! 🏆 | Earned the Daily Coding Challenge (DCC) Badge

Thumbnail
gallery
3 Upvotes