2026 May 23 Problems

45 views
Skip to first unread message

daryl...@gmail.com

unread,
May 23, 2026, 12:39:59 PMMay 23
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.




We will have a different Zoom meeting that Bhupathi is providing this week:

Here is the meeting url:

Full details:

Topic: Leet Code meeting
Time: Mar 28, 2026 10:00 AM Pacific Time (US and Canada)
        Every week on Sat, 110 occurrence(s)
Please download and import the following iCalendar (.ics) files to your calendar system.
Weekly: https://us05web.zoom.us/meeting/tZYocuqgqzMuH9IuHUphHIiZ_4T4IndJLToX/ics?icsToken=DJFc88pL6-me_TneLwAALAAAAA70ShjYgLH6RfEnqUm5LK03v2OgtbXujwlKXRMVgIVWCY9aONPJMCycMlkhyPZ3XSrMVVgXDSYlGF_r7DAwMDAwMQ&meetingMasterEventId=MGJmt5lJTd6mPygcS0hiAQ
Join Zoom Meeting
https://us05web.zoom.us/j/82553858456?pwd=fnK5Vb0CcfFpv0lnouILjeEs2z2Khc.1

Meeting ID: 825 5385 8456
Passcode: 182596

Anuj Patnaik

unread,
May 23, 2026, 1:29:59 PMMay 23
to leetcode-meetup
import heapq
class Solution:
def findXSum(self, nums: List[int], k: int, x: int) -> List[int]:
counts = 0
answer = []
if len(nums) < x:
return [sum(nums)]
for i in range(len(nums) - k + 1):
curr_nums = nums[i: i + k]
if i == 0:
counts = Solution.count_freq(curr_nums)
prev_index = counts
else:
if 0 < i and i < len(nums) - k + 1:
prev_index[nums[i - 1]] -= 1
prev_index[nums[i + k - 1]] += 1
counts = prev_index
top_x_values = Solution.calculate_x_highest_freq(counts, x)
sum_ = 0
for j in range(len(top_x_values)):
curr = top_x_values[j]
elem = curr[0]
freq = curr[1]
sum_ += elem * freq
answer.append(sum_)
return answer
def count_freq(nums):
elem_freq = defaultdict(int)
for i in range(len(nums)):
elem_freq[nums[i]] += 1
return elem_freq
def calculate_x_highest_freq(cts, x):
items = []
for i in cts.items():
items.append((i[1], i[0]))
top_x = heapq.nlargest(x, items)
return top_x

Allen S.

unread,
May 23, 2026, 11:47:58 PMMay 23
to leetcode-meetup
func findXSum(nums []int, k int, x int) []int {
n := len(nums)
res := make([]int, n - k + 1)
for i := range n - k + 1 {
res[i] = getXSum(nums[i:i+k], x)
}
return res
}

func getXSum(nums []int, x int) int {
key2count := [51]int{}
for _, v := range nums {
key2count[v]++
}
count2keys := [51][51]bool{}
for key, count := range key2count {
count2keys[count][key] = true
}
res := 0
for i := len(count2keys) - 1; i >= 0 && x > 0 ; i-- {
for j := len(count2keys[0]) - 1; j >= 0 && x > 0; j-- {
if count2keys[i][j] {
res += j * i
x--
}
}
}

return res
}
Reply all
Reply to author
Forward
0 new messages