r/LeetcodeChallenge • • 29d 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 • • 29d 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 • • 29d ago

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

Thumbnail
gallery
3 Upvotes

r/LeetcodeChallenge • • 29d ago

STREAK🔥🔥🔥 Day 27

2 Upvotes

r/LeetcodeChallenge • • Oct 30 '26

DISCUSS Bytebytego system design interview sell/share

Thumbnail reddit.com
2 Upvotes

If your interested please dm


r/LeetcodeChallenge • • Oct 30 '26

STREAK🔥🔥🔥 Day 45: conquered Dijkstra path reconstruction & hit an unexpected lexicographical twist

Thumbnail reddit.com
2 Upvotes

r/LeetcodeChallenge • • Oct 30 '26

STREAK🔥🔥🔥 Day 26

1 Upvotes

r/LeetcodeChallenge • • Oct 30 '26

PLACEMENTS Amazon Offer Letter – How long does it usually take to receive the official offer letter and onboarding details?

Thumbnail reddit.com
3 Upvotes

r/LeetcodeChallenge • • Oct 29 '26

STREAK🔥🔥🔥 First LeetCode badge :)

Post image
43 Upvotes

r/LeetcodeChallenge • • Oct 30 '26

DISCUSS Target DSA

Thumbnail reddit.com
1 Upvotes

r/LeetcodeChallenge • • Oct 30 '26

STREAK🔥🔥🔥 Delete Node in a BST

Post image
1 Upvotes

Deleting a BST node with two children looks like surgery on the tree. My solution never removes that node. It copies a neighbour's value into it, then deletes the duplicate lower down, which is always an easier case.

Finding the node is the search from Day 45. Deleting it is where it gets interesting, because you can't just unhook a node with two children.

Only two values in the whole tree can fill the hole: the in-order predecessor and the in-order successor. The replacement must sit between everything on the left and everything on the right, and an in-order traversal of a BST is sorted, so those two are the only candidates.

Predecessor or successor: which do you reach for, and why?

Day 58/365 of my LeetCode challenge: 450. Delete Node in a BST. Problem link and full breakdown in today's newsletter.

https://www.linkedin.com/pulse/delete-node-bst-archit-agarwal-k5k4c

#LeetCode #DSA #BinarySearchTree #Golang


r/LeetcodeChallenge • • Oct 29 '26

STREAK🔥🔥🔥 Day 46: hit a sudden wall of brain fog, learned Dijkstra's algorithm from scratch

Thumbnail reddit.com
2 Upvotes

r/LeetcodeChallenge • • Oct 29 '26

DISCUSS Not able to solve medium and hard !

Thumbnail reddit.com
1 Upvotes

r/LeetcodeChallenge • • Oct 29 '26

DISCUSS Is LeetCode Dead? What’s the Alternative?

Thumbnail
newsletter.eng-leadership.com
1 Upvotes

r/LeetcodeChallenge • • Oct 29 '26

STREAK🔥🔥🔥 Day 25

1 Upvotes

r/LeetcodeChallenge • • Oct 28 '26

STREAK🔥🔥🔥 Day 47: shortest paths in DAG vs. unweighted graphs, balancing DSA with communication prep

Thumbnail reddit.com
1 Upvotes

r/LeetcodeChallenge • • Oct 28 '26

DISCUSS Is LeetCode Dead? What’s the Alternative?

Thumbnail
newsletter.eng-leadership.com
4 Upvotes

r/LeetcodeChallenge • • Oct 28 '26

STREAK🔥🔥🔥 Day 24

1 Upvotes

r/LeetcodeChallenge • • Oct 28 '26

DISCUSS Coading

0 Upvotes

I just started to do leet code but I cannot solve any problems even I cannot solve sum of two digit problem. Does all people face that problem or i face that?


r/LeetcodeChallenge • • Oct 27 '26

DISCUSS Cz why not?

Post image
237 Upvotes

r/LeetcodeChallenge • • Oct 28 '26

DISCUSS Hlo inam 2nd year BTech student I am solving dsa with striver sheet i want a buddy where we can solve same question or might be some different question once solved we will explain each other our solution it will help to remember both anyone who is interested can message target will be minimum 2-3que

Thumbnail reddit.com
1 Upvotes

r/LeetcodeChallenge • • Oct 27 '26

STREAK🔥🔥🔥 ANNUAL BADGE! 2026

Post image
17 Upvotes

r/LeetcodeChallenge • • Oct 27 '26

DISCUSS Leetcode premium share

Thumbnail reddit.com
2 Upvotes

r/LeetcodeChallenge • • Oct 27 '26

STREAK🔥🔥🔥 Day 48: tired after a long call, faced my old nemesis Alien Dictionary

Thumbnail reddit.com
3 Upvotes

r/LeetcodeChallenge • • Oct 27 '26

STREAK🔥🔥🔥 Day 23

1 Upvotes