2025 November 8 Problems

69 views
Skip to first unread message

daryl...@gmail.com

unread,
Nov 8, 2025, 12:40:56 PM (4 days ago) Nov 8
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.




I'll see if we can set up an alternate Zoom meeting without the time limit, so the meeting invite will be posted later.

Anuj Patnaik

unread,
Nov 8, 2025, 1:10:16 PM (4 days ago) Nov 8
to leetcode-meetup
class Solution:
def frequencySort(self, nums: List[int]) -> List[int]:
counts = defaultdict(int)
for i in nums:
counts[i] += 1
counts_to_items = defaultdict(list)
for j in counts:
counts_to_items[counts[j]].append(j)
sorted_counts_to_items = sorted(counts_to_items.items(), key = lambda x: x[0])
print(sorted_counts_to_items)
for k in range(len(sorted_counts_to_items)):
if len(sorted_counts_to_items[k][1]) > 1:
sorted_counts_to_items[k][1].sort()
sorted_counts_to_items[k][1].reverse()
print(sorted_counts_to_items)
final_arr = []
for l in sorted_counts_to_items:
for m in l[1]:
for n in range((l[0])):
final_arr.append(m)
print(final_arr)
return final_arr

Bhupathi Kakarlapudi

unread,
Nov 8, 2025, 1:29:32 PM (4 days ago) Nov 8
to leetcod...@googlegroups.com
Let's try this google meetup link for group discussion today. 

--
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/bdff4d8a-efc4-4397-bd4a-e5fb634ebc85n%40googlegroups.com.

Bhupathi Kakarlapudi

unread,
Nov 8, 2025, 2:17:19 PM (4 days ago) Nov 8
to leetcod...@googlegroups.com
from collections import Counter

class Solution:
def frequencySort(self, nums: List[int]) -> List[int]:
freq = Counter(nums)
return sorted(nums, key=lambda x: (freq[x], -x))

On Sat, Nov 8, 2025 at 10:10 AM Anuj Patnaik <patnai...@gmail.com> wrote:
--

Allen S.

unread,
Nov 8, 2025, 2:18:20 PM (4 days ago) Nov 8
to leetcode-meetup
func frequencySort(nums []int) []int {
freqCount := map[int]int{}
for _, v := range nums {
freqCount[v]++
}

freqs := []freqRecord{}
for val, freq := range freqCount {
freqs = append(freqs, freqRecord{
val: val,
freq: freq,
})
}

slices.SortFunc(freqs,
func(a, b freqRecord) int {
return cmp.Or( // return first non zero
cmp.Compare(a.freq, b.freq),
cmp.Compare(b.val, a.val),
)
},
)
res := make([]int, 0, len(nums))
for _, v := range freqs {
for range v.freq {
res = append(res, v.val)
}
}
return res
}

type freqRecord struct {
val int
freq int
}

Anuj Patnaik

unread,
Nov 8, 2025, 2:21:07 PM (4 days ago) Nov 8
to leetcode-meetup
class Solution:
def waysToFillArray(self, queries: List[List[int]]) -> List[int]:
answer = []
for i in range(len(queries)):
answer.append(Solution.count_product_ways_prime_factorization(queries[i][0], queries[i][1]) % ((10**9) + 7))
return answer
def get_prime_factorization(num):
i = 2
factors = defaultdict(int)
while i * i <= num:
while num % i == 0:
factors[i] += 1
num //= i
i += 1
if num > 1:
factors[num] += 1
return factors

def count_product_ways_prime_factorization(n, k):
if k == 1:
return 1
prime_factors = Solution.get_prime_factorization(k)
total_ways = 1
for exponent in prime_factors.values():
total_ways *= math.comb(exponent + n - 1, n - 1)
return total_ways

Marco Guadiana

unread,
Nov 8, 2025, 2:23:51 PM (4 days ago) Nov 8
to leetcode-meetup
Screenshot 2025-11-08 112053.png

daryl...@gmail.com

unread,
Nov 8, 2025, 2:30:54 PM (4 days ago) Nov 8
to leetcode-meetup
Want to highlight that we'll be using this link for the discussion today: https://meet.google.com/xnn-kifj-jnx?pli=1 

prathyusha prathyusha

unread,
Nov 8, 2025, 2:42:29 PM (4 days ago) Nov 8
to leetcode-meetup
"""
an interger array is given.
find the frequency of the values
and then sort the numbers based on thier frequeny in ascending order
if multiple values have same frequenvy then larger number comes first

Walkthrough:

nums = [1,1,2,2,2,3]

based on their frequency, print the key value number of times

rephrase your idea.
[2,3,1,3,2]
1, 3, 3, 2,2
[-1,1,-6,4,5,-6,1,4,1]

-1:1
-6:2
1:3
4:2
5:1

5,-1,4,4,-6,-6,1,1,1

approach
take ordered dict
first iterate through teh list and then add to the dictionary
sort the dictionary by values in asc and then by keys in desc

then iterate through the dict and print the key value number of times into a result list

challenge how to you order by value and keys at the same time
3,1,1,2, 2, 2

"""
# from collections import OrderedDict
# ordereddict is not needed as we need t sort it anyway and ponce it is sorted, you can iterete it dictrectly you dont need a ordered dict
class Solution:
    def frequencySort(self, nums: List[int]) -> List[int]:
        dct = dict()
        res = []

        for i in nums:
            dct[i] = dct.setdefault(i,0)+1
       
        sorted_dct = sorted(dct.items(),key = lambda x:(x[1],-x[0]))

        for key, val in sorted_dct:
            res.extend([key]*val)

        return res

       
       

Anuj Patnaik

unread,
Nov 8, 2025, 3:17:09 PM (4 days ago) Nov 8
to leetcode-meetup

Carlos Green

unread,
Nov 8, 2025, 3:27:21 PM (4 days ago) Nov 8
to leetcode-meetup
/**
* @param {number[]} nums
* @return {number[]}
*/
var frequencySort = function(nums) {
const result = []

const freq = nums.reduce((a,c) => {
a[c] = (a[c] || 0) + 1
return a
}, {})

const pairs = Object.entries(freq).sort((a,b) => {
if (a[1] === b[1]) {
return b[0] - a[0]
}
return a[1] - b[1]
})

for (let pair of pairs) {
while(pair[1]) {
result.push(+pair[0])
pair[1]--
}
}

return result
};
Reply all
Reply to author
Forward
0 new messages