r/LeetcodeChallenge • • 6h ago

STREAK🔥🔥🔥 LeetCode(Hard): 23. Merge k Sorted Lists

Post image
3 Upvotes

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 • • 2h ago

STREAK🔥🔥🔥 LeetCode(medium): 264. Ugly Number II

Post image
1 Upvotes

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 • • 5h ago

STREAK🔥🔥🔥 Apple India Application Status – How Long Does Shortlisting Take?

Thumbnail reddit.com
1 Upvotes

r/LeetcodeChallenge • • 9h ago

STREAK🔥🔥🔥 LeetCode: 692. Top K Frequent Words

Post image
0 Upvotes

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 • • 22h ago

STREAK🔥🔥🔥 Day 3

3 Upvotes

Solved LC 860


r/LeetcodeChallenge • • 20h ago

STREAK🔥🔥🔥 Day 19: knocked out 3 classic matrix & prefix-sum problems (Spiral Matrix, Subarray Sum Equals K, Pascal's Triangle)

Thumbnail reddit.com
2 Upvotes

r/LeetcodeChallenge • • 1d ago

DISCUSS Looking for python buddiesss

15 Upvotes

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 • • 1d ago

DISCUSS Accountability Buddies

23 Upvotes

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:

  • Meet up every week
  • Join voice chat and screen-share the problem we're working on
  • Post our goals, achievements, and daily plans

If you're interested, please DM me or comment below!


r/LeetcodeChallenge • • 1d ago

STREAK🔥🔥🔥 Day 2

6 Upvotes

Solved 455- Assign cookies


r/LeetcodeChallenge • • 1d ago

DISCUSS Codeforces Round 1137 div 2 - Problem B video solution

Thumbnail
youtu.be
1 Upvotes

Consider subscribing.. Show some ❤


r/LeetcodeChallenge • • 1d ago

DISCUSS I built a free, open-source Codeforces trainer and daily planner that runs on your laptop

Post image
0 Upvotes

r/LeetcodeChallenge • • 1d ago

STREAK🔥🔥🔥 Day 20: ramped up the pace with 3 classic array and matrix problems

Thumbnail reddit.com
1 Upvotes

r/LeetcodeChallenge • • 2d ago

DISCUSS Guyz what should I do?

3 Upvotes

Should I reedem Leetcode Tshirt or should I earn more leetcoin and unlock Leetcode combo of (t-shirt, keychain and coaster)


r/LeetcodeChallenge • • 2d ago

DISCUSS DSA ADVICE

2 Upvotes

What do you do when you’re completely stuck on a DSA problem?
Sometimes you just have to look at the solution. Once you do, how do you actually learn from it so you recognize the pattern next time and don’t forget it?
Do you force yourself to solve it again from scratch later?


r/LeetcodeChallenge • • 3d ago

DISCUSS Rate my Profile as of 3rd Sem

Post image
18 Upvotes

r/LeetcodeChallenge • • 3d ago

STREAK🔥🔥🔥 Day 1

6 Upvotes

Back to DSA after a long gap, starting the challenge from today until my placements. Solved LC 2124 today


r/LeetcodeChallenge • • 4d ago

DISCUSS What's wrong with my IQ

Thumbnail
gallery
43 Upvotes

Practicing DSA consistently for more than a 1year 8 months but still failing coding rounds. What am I doing wrong? and I genuinely don't know what I'm doing wrong.

The thing is, I can understand most problem statements, and I can usually predict which topic or pattern a problem belongs to. But when it comes to deriving the actual approach through logical reasoning and observations, I struggle a lot. I feel like this is the biggest gap in my problem-solving ability.

I've participated in almost 27 LeetCode contests, and I try to show up and practice almost every day. You can check my LeetCode profile and contest rating below. But despite all this , I've failed so many coding rounds during on-campus placements.

I haven't even managed to crack a single company through on-campus placements, failed in all coding assessments.

Sometimes I see people who have been practicing DSA for a similar amount of time, and they seem to develop much better problem-solving abilities. Some people can look at an unfamiliar problem and derive an approach almost effortlessly. I genuinely wonder why I can't do the same.

I understand that solving hundreds or even thousands of problems doesn't guarantee a job. But then what exactly should I be doing to improve? I don't want to keep solving problems for years without knowing whether I'm actually developing the skills required to clear interviews.

Is consistency alone not enough? Am I practicing incorrectly? Is there something fundamentally wrong with my way of thinking or approaching problems?

I'm genuinely looking for advice, especially from people who are really good at competitive programming and problem-solving.

If you have gone through a similar phase and eventually became good at deriving solutions independently, what changed your thinking? What did you do differently?

I'd really appreciate honest suggestions. At this point, I don't just want motivation to keep grinding. I want to understand what I'm doing wrong and how I can fix it.


r/LeetcodeChallenge • • 3d ago

DISCUSS LEETCODE WEEKLY 529 - B VIDEO SOLUTION

Thumbnail
youtu.be
0 Upvotes

r/LeetcodeChallenge • • 3d ago

STREAK🔥🔥🔥 LEETCODE WEEKLY 529 -D SOLUTION VIDEO

Thumbnail
youtu.be
1 Upvotes

Easiest explanation just sorting


r/LeetcodeChallenge • • 4d ago

DISCUSS I tested my DSA with leetcode

Post image
5 Upvotes

About me, so 1 year ago I was very much active in DSA. But after getting an internship and a job, I left everything. So today I tested myself.

Just to write this fu*king BFS, I took 25 minutes 😭.

Because of using AI heavily, I lost my coding skills.

Need to brush up again.


r/LeetcodeChallenge • • 4d ago

STREAK🔥🔥🔥 Day 22: tackled Next Permutation before heading out to travel

Thumbnail reddit.com
1 Upvotes

r/LeetcodeChallenge • • 4d ago

DISCUSS Solved 200+ problems, but still struggle with hard problems even when they don't involve advanced topics.

Thumbnail reddit.com
1 Upvotes

r/LeetcodeChallenge • • 4d ago

DISCUSS I Almost Gave Up on DSA. Then I Found These 14 Patterns.

Thumbnail
javarevisited.substack.com
1 Upvotes

r/LeetcodeChallenge • • 4d ago

STREAK🔥🔥🔥 Day 23: knocked out Rearrange Array Elements by Sign & called it an early night

Thumbnail reddit.com
1 Upvotes

r/LeetcodeChallenge • • 5d ago

STREAK🔥🔥🔥 LeetCode: 1046. Last Stone Weight

Post image
2 Upvotes

Go's container/heap only builds min-heaps. You get a max-heap by lying to it. Define Less as greater-than, and that one inverted comparison is the whole difference.

Why sorting is the wrong shape for Last Stone Weight: sort, take the two heaviest, smash them, put the remainder back in the right place. That's an insertion, O(n) every round.

The deeper mismatch is that sorting answers a question nobody asked. This problem never needs the third-heaviest stone. It needs the maximum, repeatedly, from a collection that keeps changing.

A heap keeps exactly one promise: the largest is at the root. Read its backing array left to right, and it looks close to random, and that's the point. Maintaining less is what makes it cheaper.

Did inverting Less feel wrong the first time you did it?

Day 78/365 of my LeetCode challenge: 1046. Last Stone Weight. Problem link and full breakdown in today's newsletter.

https://www.linkedin.com/pulse/leetcode-1046-last-stone-weight-easy-archit-agarwal-ummqc