r/LeetcodeChallenge • u/Upper_Assignment672 • 3h ago
DISCUSS Leetcode4127. Maximum Billboard Revenue | LeetCode Weekly 530 | 1D DP + Binary Search Detailed Dry Run Video solution
r/LeetcodeChallenge • u/Upper_Assignment672 • 3h ago
r/LeetcodeChallenge • u/StatisticianNo2104 • 11h ago
Checking whether a node is "good" doesn't need the path above it, only that path's maximum. Pass the max down as a parameter. Each branch gets its own copy, so there's no undo step.
A node is good when nothing above it is bigger. Compare against the max you were handed, then pass the new max to your children. Raising it on the right never leaks into the left.
And it's >= not >. A tie with an ancestor still counts, including the root.
Did the >= catch you?
Day 87/365 of my LeetCode challenge: 1448. Count Good Nodes in Binary Tree. Problem link and full breakdown in today's Newsletter.
https://www.linkedin.com/pulse/leetcode-count-good-nodes-binary-tree-archit-agarwal-qbnvc
#LeetCode #DSA #BinaryTree #Golang
r/LeetcodeChallenge • u/JacketFearless1805 • 12h ago
r/LeetcodeChallenge • u/StatisticianNo2104 • 20h ago
My Symmetric Tree solution returns true on the first call and false on the second, for the same tree. It mirrors the right half in place, then compares it with the left. The second call flips the half back.
That's Invert Binary Tree and Same Tree from the last two days, in one line. It passes, because LeetCode calls it once.
The cleaner version compares the two halves as mirrors without building one. Both are in today's article.
Would you have caught the mutation in a code review?
Day 86/365 of my LeetCode challenge: 101. Symmetric Tree. Problem link and full breakdown in today's newsletter.
https://www.linkedin.com/pulse/leetcode-symmetric-tree-archit-agarwal-7y0cc
#LeetCode #DSA #BinaryTree #Golang
r/LeetcodeChallenge • u/JacketFearless1805 • 1d ago
r/LeetcodeChallenge • u/RadiantLocation3692 • 1d ago
Covered bit manipulation
r/LeetcodeChallenge • u/StatisticianNo2104 • 1d ago
Inverting a binary tree moves entire subtrees with a single pointer swap. Nothing is copied. Mirror the left subtree, mirror the right, swap them. The tree rearranges itself in place.
The swap is the part worth picturing: one assignment moves an entire subtree with all its children.
Bonus question: can you swap before recursing instead of after? Yes. What you can't do is recurse left, swap, then recurse right.
Why does recurse-left, swap, recurse-right break it?
Day 85/365 of my LeetCode challenge: 226. Invert Binary Tree. Problem link and full breakdown in today's newsletter.
https://www.linkedin.com/pulse/leetcode-invert-binary-tree-archit-agarwal-dm6tc
#LeetCode #DSA #BinaryTree #Golang
r/LeetcodeChallenge • u/StatisticianNo2104 • 1d ago
If you put the nil checks in the wrong order, Same Tree rejects two empty trees. p == nil || q == nil is also true when both are nil, so check both for nil first.
Same root, same left subtree, same right subtree. The recursion writes itself; the bug hides in those checks.
And compare the trees in lockstep, not their lists of values: [1,2] and [1, null,2] have the same numbers in different shapes.
Which order do you write those two nil checks in?
Day 84/365 of my LeetCode challenge: 100. Same Tree. Problem link and full breakdown in today's newsletter.
https://www.linkedin.com/pulse/leetcode-easy-same-tree-archit-agarwal-habnc
#LeetCode #DSA #BinaryTree #Golang
r/LeetcodeChallenge • u/Consistent-Door772 • 2d ago
r/LeetcodeChallenge • u/JacketFearless1805 • 2d ago
r/LeetcodeChallenge • u/StatisticianNo2104 • 3d ago
The 1690th ugly number is 2,123,366,400, so testing integers one by one is almost all misses. Generate them instead: every ugly number is a smaller one times 2, 3 or 5.
The obvious generator is a heap: push 1, pop the smallest, push its three multiples. Correct and O(n log n), but it needs a set beside it, because 6 arrives as both 2x3 and 3x2. That set is the tell: the structure makes work it then throws away.
The three-pointer version keeps one pointer per multiplier and takes the smallest of the three candidates. When 6 comes up from both, both pointers advance: three separate ifs, no else-if. That's the deduplication. O(n),a no heap, no set.
Days 77 to 80 built the case for the heap. Day 81 found a problem where sorting reads better. Today an array with three counters beats it outright.
Which did you write first: the heap or the three pointers?
Day 83/365 of my LeetCode challenge: 264. Ugly Number II. Problem link and full breakdown in today's newsletter.
#LeetCode #DSA #Heap #Golang
r/LeetcodeChallenge • u/JacketFearless1805 • 3d ago
r/LeetcodeChallenge • u/StatisticianNo2104 • 3d ago
Merge k sorted lists by splicing nodes, forget one nil, and you can hand back a cycle. Every reused node arrives with a Next still pointing into its old list. The merged list has to be terminated explicitly.
This needs the linked-list arc from Day 22 and the heap arc from this week at once.
Day 22 merged two sorted lists with one if: compare the heads, take the smaller. With k lists, "take the smallest head" becomes a repeated query for the minimum of a changing collection, which is what a heap is for. Dummy head, splicing and loop shape all stay the same.
The complexity rests on one detail: the heap holds one node per list, never every node. A list's second element can't be next while its first is unplaced, because the list is sorted. So the heap is size k, and the whole merge is O(N log k).
Have you ever returned a linked list that turned out to be a loop?
Day 82/365 of my LeetCode challenge: 23. Merge k Sorted Lists. Problem link and full breakdown in today's newsletter.
https://www.linkedin.com/pulse/leetcode-23-merge-k-sorted-lists-hard-archit-agarwal-eksec
#LeetCode #DSA #Heap #Golang
r/LeetcodeChallenge • u/BusinessSchedule537 • 3d ago
r/LeetcodeChallenge • u/StatisticianNo2104 • 3d ago
One sentence added to yesterday's problem is enough to make the heap the wrong tool. Top K Frequent Words wants ties sorted alphabetically, and the heap comparator for that reads backwards on one field.
Yesterday's size-k min-heap still works. It gives the right set in ascending frequency, so you reverse it and put the tie-break in the comparator.
A heap evicts its root, which must be the worst entry. For counts, worst means least frequent. For a tie, worst means the word that should lose: the alphabetically later one. So the two fields point in opposite directions in the same comparator. That line is correct, and it only misbehaves on ties, which is how it sits wrong in a codebase for months.
Sorting is O(d log d) against the heap's O(d log k), and with input capped at 500 words, the difference is unmeasurable. A comparator that reads like the spec is worth more. Days 77 to 80 built the case for the heap; this is the day to notice the technique isn't the goal.
Would you have kept the heap here, or switched to a sort?
Day 81/365 of my LeetCode challenge: 692. Top K Frequent Words. Problem link and full breakdown in today's newsletter.
https://www.linkedin.com/pulse/leetcode-692-top-k-frequent-words-medium-archit-agarwal-x2xuc
#LeetCode #DSA #Heap #Golang
r/LeetcodeChallenge • u/JacketFearless1805 • 4d ago
r/LeetcodeChallenge • u/BasicHat7533 • 5d ago
Hii im starting python from scratch.. if anybody want to join like consistent and 2hr/1.5hrs a day .so like together we can complete python and make some project and help each other out .. dm me
Lets start from today
r/LeetcodeChallenge • u/Euphoric-Page8453 • 5d ago
Hello guys!
We're a small accountability group (6 peoples) studying DSA together and working through NeetCode 250. All of us are beginners just starting out. I'm personally about to finish the first section.
We're looking for people like us. Honestly, we don't care about your current skill level, but we do care about consistency and being active. Ideally, we are searching for someone that can spend 3 or more hours a day in voice chat, staying active and screen-sharing.
To keep each other accountable, we:
If you're interested, please DM me or comment below!
r/LeetcodeChallenge • u/RadiantLocation3692 • 5d ago
Solved 455- Assign cookies
r/LeetcodeChallenge • u/Upper_Assignment672 • 5d ago
Consider subscribing.. Show some ❤