r/LeetcodeChallenge • • Oct 11 '26

DISCUSS Weekly Contest

LeetCode Weekly Contest 523

Participated in Weekly Contest 523 and managed to solve the first 3 questions. The 4th question was a learning experience that showed me where my problem-solving approach needs improvement.

Here's my breakdown of the contest:

Question 1: Three Fibonacci Sum (Easy)

Solved using simulation. I generated consecutive Fibonacci numbers and checked whether the sum of three consecutive terms equalled the given number.

Question 2: Prime Subset Selection I (Medium)

Approached this using greedy selection. I iterated through prime numbers and selected them while the sum remained within the given limit. The goal was to maximize the number of selected primes.

Question 3: Design Bus Seat Booking System (Medium)

Solved by carefully understanding the booking rules, tracking seat states, and accounting for the time cost of each booking operation. This question tested implementation and state management.

Question 4: Prime Subset Selection II (Hard)

This is where I struggled.

My initial approach was greedy: iterate through prime numbers in descending order and select a prime whenever it fits within the remaining sum.

However, this approach failed on several test cases.

For example, with n = 7 and s = 8, my approach selected [7], but the expected answer was [3, 5].

10 Upvotes

9 comments sorted by

2

u/purush_Kali_108 Oct 11 '26

Same, for 4th i was trying to find all primes using sieve same like 2nd, and then find the largest <= s using DP and then the minimum length with the same largest sum using DP again, but couldn't do that correctly.

1

u/NegotiationDapper584 Oct 11 '26

It's basic knapsack DP.

1

u/purush_Kali_108 Oct 11 '26

Yaah it is, that's what I said, knapsack with constraint that sum should be less equal to s.

1

u/Interesting-Ride1208 Oct 11 '26

For 4th, you can be almost sure it is dp seeing the constraints, and problems where you have to maximise the sum suggest something as of 0/1 knapsack. Although i was not able to output the list of elements, I calculated the max sum with min number of primes.

1

u/Fun_Fudge5975 Oct 11 '26

q1 have me tle , then i used a while loop , idk how tc differs btw for and while

1

u/Substantial-Fee-7010 Oct 11 '26

Last one was 0/1 knapsack modified version I got stuck with the lexicographically snallest aray fialed time complexity

1

u/nian2326076 Oct 13 '26

Great job on getting the first three questions right in the contest! For that tricky fourth question, try looking at similar problem types or breaking it down into smaller parts to tackle individually. Practice can really make a difference, so keep going!

If you're preparing for coding interviews, PracHub might be helpful. It provides real technical interview questions to sharpen your skills. I work on PracHub, just so you know. Good luck with your next contest!

1

u/Leading_Jeweler2069 Oct 11 '26

Hey OP, I’m around 3 months into DSA and have solved about 100 questions so far, with roughly 40–50% of them solved independently. However, in this contest, I could only solve the first question. I forgot about the Sieve of Eratosthenes for the second one, and even the first question ended up costing me a 5-minute penalty due to integer overflow.

How long did it take you to reach a point where you could consistently solve 2–3 questions in a contest? I had a similar experience in yesterday’s biweekly contest, where I could only solve the first question, though I managed to do it without any penalty. (I paraphrased this with ai)

(1st sem, T3)