2025 November 22 Problems

83 views
Skip to first unread message

daryl...@gmail.com

unread,
Nov 22, 2025, 12:41:32 PMNov 22
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.

Sort problem has been carried for people to finish up the work they started last week.

912. Sort an Array Medium 56.1%



We're going to try to use the same Google meet link as last time: https://meet.google.com/xnn-kifj-jnx?pli=1 Hopefully this time we get the annotation add-ons working.

Gayathri Ravichandran

unread,
Nov 22, 2025, 12:58:15 PMNov 22
to leetcod...@googlegroups.com
Hi, 
Do you all meet at the library or only on Google meet?

Thanks,
Gayathri 

--
whatspp group: http://whatsapp.techbayarea.us/
---
You received this message because you are subscribed to the Google Groups "leetcode-meetup" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leetcode-meet...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/leetcode-meetup/43461ce8-c5d1-43a7-b6ef-91aa1ee33a8an%40googlegroups.com.

FloM

unread,
Nov 22, 2025, 1:09:54 PMNov 22
to leetcode-meetup
Hi Gayathri,
Daryl may be a little late to the library. People (at least Daryl) meet at the "Tech Center" in the library. When you enter the library turn right and it's a glass enclosed room. 
-Flo

Allen S.

unread,
Nov 22, 2025, 1:46:51 PMNov 22
to leetcode-meetup
func matchPlayersAndTrainers(players []int, trainers []int) int {
// preprocessing
slices.Sort(players)
slices.Sort(trainers)
j := 0
result := 0
for i := range players {
for j < len(trainers) {
if players[i] <= trainers[j] {
result++
j++
break
}
j++
}
}
return result
}

Anuj Patnaik

unread,
Nov 22, 2025, 1:52:20 PMNov 22
to leetcode-meetup
class Solution:
def matchPlayersAndTrainers(self, players: List[int], trainers: List[int]) -> int:
sorted_players = Solution.sort(self, players)
sorted_trainers = Solution.sort(self, trainers)
i = 0
j = 0
num_matches = 0
while i < len(sorted_players) and j < len(sorted_trainers):
if sorted_players[i] <= sorted_trainers[j]:
num_matches += 1
i += 1
j += 1
else:
j += 1
return num_matches

def sort(self, nums: List[int]) -> List[int]:
if len(nums) == 1:
return nums
mid = len(nums) // 2
left_merge_arr = nums[0: mid]
right_merge_arr = nums[mid:]
left_sort = Solution.sort(self,left_merge_arr)
right_sort = Solution.sort(self, right_merge_arr)
return Solution.merge(left_sort, right_sort)




def merge(left_arr, right_arr):
merged_arr = []
i = 0
j = 0
while i < len(left_arr) and j < len(right_arr):
if left_arr[i] < right_arr[j]:
merged_arr.append(left_arr[i])
i = i + 1
elif left_arr[i] > right_arr[j]:
merged_arr.append(right_arr[j])
j = j + 1
else:
merged_arr.append(right_arr[j])
merged_arr.append(left_arr[i])
i += 1
j += 1
while i < len(left_arr):
merged_arr.append(left_arr[i])
i = i + 1
while j < len(right_arr):
merged_arr.append(right_arr[j])
j = j + 1

return merged_arr

Anuj Patnaik

unread,
Nov 22, 2025, 1:54:33 PMNov 22
to leetcode-meetup
class Solution:
def sortArray(self, nums: List[int]) -> List[int]:
if len(nums) == 1:
return nums
mid = len(nums) // 2
left_merge_arr = nums[0: mid]
right_merge_arr = nums[mid:]
left_sort = Solution.sortArray(self,left_merge_arr)
right_sort = Solution.sortArray(self, right_merge_arr)
return Solution.merge(left_sort, right_sort)




def merge(left_arr, right_arr):
merged_arr = []
i = 0
j = 0
while i < len(left_arr) and j < len(right_arr):
if left_arr[i] < right_arr[j]:
merged_arr.append(left_arr[i])
i = i + 1
elif left_arr[i] > right_arr[j]:
merged_arr.append(right_arr[j])
j = j + 1
else:
merged_arr.append(right_arr[j])
merged_arr.append(left_arr[i])
i += 1
j += 1
while i < len(left_arr):
merged_arr.append(left_arr[i])
i = i + 1
while j < len(right_arr):
merged_arr.append(right_arr[j])
j = j + 1

return merged_arr

Rudy W

unread,
Nov 22, 2025, 2:33:15 PMNov 22
to leetcod...@googlegroups.com
class Solution:

# let's use merge sort
def sortArray(self, nums: List[int]) -> List[int]:
self.mergeSort(nums)
return nums

def merge(self, nums: List[int], left_part: List[int], right_part: List[int]):
p1 = p2 = 0
i = 0

while p1 < len(left_part) and p2 < len(right_part):
if left_part[p1] <= right_part[p2]:
nums[i] = left_part[p1]
p1 += 1

elif left_part[p1] > right_part[p2]:
nums[i] = right_part[p2]
p2 += 1
i += 1

# if we have no more right_part list to traverse, we need to check ..
# if we need to copy left_part list to nums
while p1 < len(left_part):
nums[i] = left_part[p1]
p1 += 1
i += 1
# likewise, if we have no more left_part list to traverse, we need to check ..
# if we need to copy right_part list to nums
while p2 < len(right_part):
nums[i] = right_part[p2]
p2 += 1
i += 1

def mergeSort(self, nums: List[int]):

#base case
if len(nums) <= 1:
return
# calculate mid index
mid = len(nums) // 2
left_part = nums[:mid]
right_part = nums[mid:]

self.mergeSort(left_part)
self.mergeSort(right_part)

self.merge(nums, left_part, right_part)


Gowrima Jayaramu

unread,
Nov 22, 2025, 3:17:32 PMNov 22
to leetcode-meetup
class Solution:
def matchPlayersAndTrainers(self, players: List[int], trainers: List[int]) -> int:
players.sort()
trainers.sort()
i, j, result = 0, 0, 0

for i in range(len(players)):
while j<len(trainers):
if players[i] <= trainers[j]:
result += 1
j += 1
break
j += 1

return result

Carlos Green

unread,
Nov 22, 2025, 3:58:23 PMNov 22
to leetcode-meetup
function sortArray(nums: number[]): number[] {
if (nums.length <= 1) return nums

const pivot: number = Math.floor(Math.random() * nums.length)
const value: number = nums[pivot]

const left: number[] = []
const middle: number[] = []
const right: number[] = []

for (let num of nums) {
if (num < value) {
left.push(num)
} else if (num > value) {
right.push(num)
} else {
middle.push(num)
}
}

return [
...sortArray(left),
...middle,
...sortArray(right)
]
};

Rudy W

unread,
Nov 22, 2025, 4:20:17 PMNov 22
to leetcod...@googlegroups.com
class Solution:
def matchPlayersAndTrainers(self, players: List[int], trainers: List[int]) -> int:
players.sort()
trainers.sort()

p, t = 0, 0
count = 0

while p < len(players) and t < len(trainers):
if players[p] <= trainers[t]:
p += 1
count += 1

t += 1
return count


--
whatspp group: http://whatsapp.techbayarea.us/
---
You received this message because you are subscribed to the Google Groups "leetcode-meetup" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leetcode-meet...@googlegroups.com.

FloM

unread,
Nov 22, 2025, 5:53:08 PMNov 22
to leetcode-meetup
912. Sort an Array Medium 56.1%
MergeSort Time: O(n*lgN) Mem: O(n)
class Solution {
public:

vector<int> sortArray(vector<int>& nums) {
vector<int> copy = nums;
vector<int>* from = &nums;
vector<int>* to = &copy;

int unitSize = 1;
int firstIdx = 0;
int secondIdx = unitSize;

while(unitSize < nums.size())
{
int idx = 0;
while(idx < nums.size())
{
int leftIdx = firstIdx;
int rightIdx = firstIdx + unitSize;
int idxCap = firstIdx + (unitSize*2);
while( (idx < idxCap) && (idx < nums.size()) )
{
if (leftIdx >= (firstIdx + unitSize))
{
(*to)[idx] = (*from)[rightIdx];
++rightIdx;
}
else if ( (rightIdx >= (secondIdx + unitSize)) || (rightIdx >= nums.size()) )
{
(*to)[idx] = (*from)[leftIdx];
++leftIdx;
}
else if ((*from)[leftIdx] < (*from)[rightIdx])
{
(*to)[idx] = (*from)[leftIdx];
++leftIdx;
}
else
{
(*to)[idx] = (*from)[rightIdx];
++rightIdx;
}
++idx;
}

firstIdx += (2 * unitSize);
secondIdx = firstIdx + unitSize;
}
unitSize *= 2;
firstIdx = 0;
secondIdx = unitSize;
vector<int>* temp = from;
from = to;
to = temp;
}

return *from;

}
};

Reply all
Reply to author
Forward
0 new messages