2025 May 10 Problems

70 views
Skip to first unread message

daryl...@gmail.com

unread,
May 10, 2025, 12:43:56 PMMay 10
to leetcode-meetup
Feel free to work on any of the problems you want; we'll have people present their solutions at 11:30.

Please post your solutions to this thread so others can use this as a reference.


2332. The Latest Time to Catch a Bus Medium 28.2%



Please download and import the following iCalendar (.ics) files to your calendar system.

Anuj Patnaik

unread,
May 10, 2025, 1:32:50 PMMay 10
to leetcode-meetup
class Solution:
def fillCups(self, amount: List[int]) -> int:
total_time_for_all_three = amount[0] + amount[1] + amount[2]
min_time_needed = max(amount[0], amount[1], amount[2])
return max(min_time_needed, ((total_time_for_all_three+1)//2))

daryl...@gmail.com

unread,
May 10, 2025, 2:55:36 PMMay 10
to leetcode-meetup
By popular demand we will be rolling over the medium and hard problems to next week, so heads up for everyone.

On Saturday, May 10, 2025 at 9:43:56 AM UTC-7 daryl...@gmail.com wrote:

Allen S.

unread,
May 10, 2025, 3:46:19 PMMay 10
to leetcode-meetup
// sorting solution
// time Big O(n * Log (cups))
// time Big O(1)

func fillCups(amount []int) int {
time := 0
slices.Sort(amount)
for amount[2] > 0 {
time++
if amount[1] > 0 {
amount[1]--
}
if amount[2] > 0 {
amount[2]--
}
slices.Sort(amount)
}
return time
}

Stephen M

unread,
May 11, 2025, 3:01:50 AMMay 11
to leetcode-meetup
# Algebraic solution with Time: O(1),  Space: O(1)

class Solution:

    def fillCups(self, a: List[int]) -> int:

        a.sort(reverse=True) # now we have a[0] >= a[1] >= a[2]

        if a[0] >= a[1]+a[2]:

            return a[0]

        else:

            return (sum(a)+1)//2 # sum, integer-divide-by-2, round up


Jagrut

unread,
May 12, 2025, 5:08:42 PMMay 12
to leetcode-meetup
class Solution:
def fillCups(self, amount: List[int]) -> int:
q = [-a for a in amount if a > 0]
res = 0
while len(q) > 1:
highest = -1 * heapq.heappop(q)
second_highest = -1 * heapq.heappop(q)
res += 1
if highest > 1:
heapq.heappush(q, -(highest - 1))
if second_highest > 1:
heapq.heappush(q, -(second_highest - 1))
while q:
res += -1 * heapq.heappop(q)
return res
Reply all
Reply to author
Forward
0 new messages