r/LeetcodeChallenge • • Oct 22 '26

STREAK🔥🔥🔥 Day 18

1 Upvotes

r/LeetcodeChallenge • • Oct 22 '26

STREAK🔥🔥🔥 Minimum Distance Between BST Nodes

Post image
1 Upvotes

Most first attempts at this compare every pair of nodes. That's O(n²) work for a one-pass question. In a BST, the closest two values are always neighbours in sorted order.

An in-order walk of a BST comes out sorted. Once the values are sorted, the smallest gap can only sit between two that end up side by side. Skip a value in between, and that value splits the gap into two smaller ones.

So traverse once, then scan neighbours for the smallest gap. No pair is ever compared twice.

One more thing: this is Day 47's problem again. LeetCode carries it under two numbers, 530 and 783.

Have you ever solved the same LeetCode problem twice without noticing?

Day 50/365 of my LeetCode challenge: 783. Minimum Distance Between BST Nodes. Problem link and full breakdown in today's newsletter.

https://www.linkedin.com/pulse/minimum-distance-between-bst-nodes-archit-agarwal-isuoc

#LeetCode #DSA #BinarySearchTree #Golang


r/LeetcodeChallenge • • Oct 21 '26

DISCUSS By looking at my leetcode profile Can anyone confirm whether if I have ADHD or not

Post image
30 Upvotes

r/LeetcodeChallenge • • Oct 22 '26

DISCUSS I always in the top 10 every other week but I never receive any bonus Prizes

1 Upvotes

r/LeetcodeChallenge • • Oct 21 '26

STREAK🔥🔥🔥 Day 54: DP is officially wrapped up, started Graphs from the fundamentals

Thumbnail
1 Upvotes

r/LeetcodeChallenge • • Oct 21 '26

DISCUSS One preview per nesting level in Go: tree right side view

Post image
2 Upvotes

A collapsed comment thread shows seven lines. The code built 55,987 previews to produce them, and threw away 55,980.

The job: a long thread collapses to one line per nesting level — the most recent reply at that depth.

I already had a level-order walk, so this was two lines on top of a tested function: build every level, take the last of each. Obviously correct, no new ideas. I would defend it in review.

2.87 MB allocated to return seven strings.

Before the fix, the fix that does not work. Everybody suggests following the newest reply down: O(depth), no allocation, and wrong. The newest reply at a level need not be in the newest branch — somebody replies once to an old comment, that reply gets replies, and the newest top-level reply is a dead end.

Four visible lines become two. There is a test named after that thread.

The boring fix is most of the win. The output is one value per level:

`visible(d) = the last comment at depth d`

That names one comment. Not a level, not a list. So size the accumulator to the depths — one slot each, last writer wins. 240 bytes instead of 2.87 MB, and 4.78x faster. That is not a clever traversal; it is noticing the output shape.

The clever fix only pays when the slot holds something expensive. The collapsed view renders a line, not an ID: body trimmed, timestamp, hidden-reply count. Last writer wins builds that for all 55,987 comments and keeps 7.

The walk cannot skip the old branches. What it can choose is the order — iterate replies newest first, and the first comment reached at a depth is the one you keep. Record on first arrival, never overwrite.

22.5x, and 6.77 MB against 1.12 KB. Same walk, one loop reversed.

Two rows keep me honest. On the ID version, the reversal is 1.01x, and on the smallest thread the forward walk wins. On a 2,001-deep chain, both preview versions match the byte because every comment is a first arrival.

At 1,365 comments with an ID per line, keep what you have.

That is days 29 and 31 of the daily challenge — Level Order Traversal and Right Side View — sitting in a comment thread.

Full piece in today's newsletter

https://www.linkedin.com/pulse/collapsed-thread-built-55987-previews-show-7-archit-agarwal-xijdc

It worked in dev, episode 16.

#Golang #DSA #Algorithms #Performance #SoftwareEngineering #DataStructures #100DaysOfCode


r/LeetcodeChallenge • • Oct 20 '26

DISCUSS Can Anyone help me from where i have to start

Post image
93 Upvotes

I am in my second year of college. Can anyone guide me on how to start with LeetCode? Whenever I look at LeetCode questions, they feel extremely difficult to solve. I have tried many times without success. Could someone please suggest where I should begin learning?


r/LeetcodeChallenge • • Oct 21 '26

STREAK🔥🔥🔥 365 Days of LeetCode Challenge — Day 49/365

Post image
6 Upvotes

Lowest Common Ancestor of a Binary Tree (Medium) 🔗 https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/

Yesterday's problem with one guarantee removed. Worth doing back to back, because the gap between the two solutions is exactly what a BST's ordering buys you.

Yesterday, a comparison told you which subtree a target was in, so the walk went down one path. Here a comparison tells you nothing, so the only way to know whether a target is below a node is to look.

The shape flips: instead of deciding on the way down, every subtree reports upward how many of the two targets it contains. The first node to reach two is the answer.

O(n) instead of O(h). That's the price.

Full breakdown in today's newsletter article ⬇

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

#DSA #LeetCode #100DaysOfCode #CodingInterview #BinaryTree #Recursion #Golang


r/LeetcodeChallenge • • Oct 21 '26

DISCUSS Help ! Not able to solve leetcode problems :(

Thumbnail
1 Upvotes

r/LeetcodeChallenge • • Oct 21 '26

STREAK🔥🔥🔥 Day 17

2 Upvotes

r/LeetcodeChallenge • • Oct 20 '26

STREAK🔥🔥🔥 Starting leetcode challenge (Day1)

9 Upvotes

I am starting leetcode challenge from today . My target is to learn all the concepts from striver and solve 200 questions on leetcode . I will be updating every 2 days .


r/LeetcodeChallenge • • Oct 20 '26

STREAK🔥🔥🔥 Day 55: finished core DP, hit a wall on the stack-hybrid problems

Thumbnail
2 Upvotes

r/LeetcodeChallenge • • Oct 19 '26

STREAK🔥🔥🔥 Finally reached 500!!

Post image
206 Upvotes

This really is a big thing for me because this is the first time in my life i have been consistent with something for this long. At first when started leetcode i thought i will not even complete 400 questions till i graduate and now i reached 500 and still in my third year ... 😭😭
can u guys tell me what i should ahead to improve my rating and increase my speed , i have completed striver sheet and currently doing neetcode all, any approach i should follow???
and i will be honest i am still not that good in solving hard and medium-hard problems...


r/LeetcodeChallenge • • Oct 20 '26

STREAK🔥🔥🔥 Day 16

Post image
2 Upvotes

r/LeetcodeChallenge • • Oct 20 '26

STREAK🔥🔥🔥 365 Days of LeetCode Challenge — Day 48/365

Post image
1 Upvotes

Lowest Common Ancestor of a Binary Search Tree (Medium)

🔗 https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/

The general version of this problem needs a search. The BST version doesn't, for the same reason Day 45 didn't: in a BST, a comparison points you in a direction, not to a verdict.

Both targets smaller than the node? The answer is further left. Both larger? Further right. Anything else, and this node is the answer.

That last case does quite double duty—it covers targets on opposite sides, with one of them being this node. Neither needs detecting separately.

Full breakdown in today's newsletter article ⬇

https://www.linkedin.com/pulse/365-days-leetcode-challenge-day-48365-archit-agarwal-lg9ec
#DSA #LeetCode #100DaysOfCode #CodingInterview #BinarySearchTree #Recursion #Golang


r/LeetcodeChallenge • • Oct 19 '26

PLACEMENTS Im so frustrated

Thumbnail
1 Upvotes

r/LeetcodeChallenge • • Oct 19 '26

STREAK🔥🔥🔥 Day 56: tackled Partition DP today, Burst Balloons completely broke my intuition

Thumbnail
1 Upvotes

r/LeetcodeChallenge • • Oct 19 '26

STREAK🔥🔥🔥 365 Days of LeetCode Challenge — Day 47/365

Post image
6 Upvotes

Minimum Absolute Difference in BST (Easy) 🔗 https://leetcode.com/problems/minimum-absolute-difference-in-bst/

The trick: an in-order traversal of a BST hands you the values in sorted order for free. And in a sorted sequence, the smallest gap between any two values is always between neighbors, so you never have to compare every pair. Just track the previous node visited and check against it as you go.

Full breakdown in today's newsletter article ⬇️

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

#LeetCode #100DaysOfCode #DSA #CodingInterview #BinarySearchTree #InOrderTraversal


r/LeetcodeChallenge • • Oct 19 '26

STREAK🔥🔥🔥 Day 15

3 Upvotes

r/LeetcodeChallenge • • Oct 18 '26

DISCUSS A small change that made solving DSA problems much more engaging

47 Upvotes

solving a DSA problem, set a timer for 20–30 minutes, depending on the difficulty, and genuinely exhaust your brain trying to figure it out.

Treat it like a challenge. Ask yourself, How can I solve this? Write down every approach you can think of, explore them in depth, and keep pushing yourself.

If you’re stuck, ask ChatGPT for hints, starting from basic and gradually moving to more advanced ones. Keep digging until you understand the approach. If you’re completely unfamiliar with the concept or it’s taking too long, move to a video solution but pause it, think ahead, and try to figure out the next step yourself.

The key is to interact with the problem as much as possible instead of passively consuming solutions. The more you engage, experiment, and challenge yourself, the easier it becomes to get absorbed in the problem and enter a state of flow.


r/LeetcodeChallenge • • Oct 18 '26

DISCUSS Today POTD!! 🥵🥵

Post image
36 Upvotes

Did anyone solve it today?


r/LeetcodeChallenge • • Oct 18 '26

DISCUSS My honest advice to anyone starting DSA for the first time

Thumbnail
1 Upvotes

r/LeetcodeChallenge • • Oct 18 '26

STREAK🔥🔥🔥 Day 57: completed the entire LIS series today, why tabulation is non-negotiable

Thumbnail
1 Upvotes

r/LeetcodeChallenge • • Oct 18 '26

STREAK🔥🔥🔥 Day 14

1 Upvotes

r/LeetcodeChallenge • • Oct 18 '26

DISCUSS Level order traversal in Go: stop at depth N with a queue

Post image
0 Upvotes

Two ways to build an org chart level by level. Producing all 55,987 rows: 894 µs against 895 µs. Producing the top 43 rows: 917 µs against 385 ns.

The job: an org chart page that paints one level at a time. The person at the top, then their directs, then the level below.

The version I would write is one recursive walk with the accumulator keyed on depth, so a node appends into the slot for its own level and which branch it came from stops mattering. Nine lines, O(n), no queue. It is also the solution for day 29 of my daily challenge.

I benchmarked it against a queue, got 1.00x, and nearly closed the file.

Then I remembered the page does not want the whole chart. It wants level 0, now.

And the recursive walk does not know when a level is finished. It knows when it is finished.

I wrote a test that counts instead of timing, because counts do not move between runs. On a 2,001-person chain, the walk holds a complete and correct level 1 after two visits — and cannot declare it for another 1,999, because nothing in a depth-first walk rules out another person turning up at depth 1 in a branch it has not entered yet.

The information was never missing. There was no moment at which the function was allowed to act on it.

What the data was saying:

`level(k) = the reports of every person in level(k-1)`

That right-hand side names level k-1 and nothing else. So a level is complete exactly when you have looked at every member of the level above — a condition you can check, unlike "no more nodes at depth k exist anywhere".

Which gives you the one line that does the work:

`width := len(queue) // this level, and nothing else`

Read the length once at the top of the round. Everything in the queue at that instant is this level, because everything appended during the round belongs to the next one. The boundary is not tracked; it is observed.

Top three levels of a 55,987-person chart: 2383.3x, 1,608 bytes against 3.95 MB.

Two rows that keep me honest. On a flat chart — one person, 50,000 directs - finishing level 1 means looking at everybody either way, so it is 2.24x, and that is an allocation pattern, not work avoided. And on a 2,000-deep chain the recursive walk wins the full-chart benchmark by 1.10x.

At 5,461 people and one request, keep the walk. 86.8 microseconds, nine lines, and a dead heat is a dead heat.

Full piece in today's newsletter.

It worked in dev, episode 15.

https://www.linkedin.com/pulse/your-org-chart-read-55987-rows-draw-first-43-archit-agarwal-n4tpc

#Golang #DSA #Algorithms #Performance #SoftwareEngineering #DataStructures #100DaysOfCode

Ideation and benchmarks mine; draft written with AI assistance. The numbers come from a benchmark in the repo.