2025 December 20 Problems

51 views
Skip to first unread message

daryl...@gmail.com

unread,
Dec 20, 2025, 12:47:46 PM (3 days ago) Dec 20
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.

Porting over LFU problem; for those of you around last week the solution will be a twist on the LRU cache we went.


2405. Optimal Partition of String Medium 78.3%

460. LFU Cache Hard 48.0%

We're going to try to use the same Google meet link as the last few times: https://meet.google.com/xnn-kifj-jnx?pli=1

Anuj Patnaik

unread,
Dec 20, 2025, 1:07:14 PM (3 days ago) Dec 20
to leetcode-meetup
class Solution:
def repeatedCharacter(self, s: str) -> str:
seen = set()
for i in s:
if i in seen:
return i
seen.add(i)

Anuj Patnaik

unread,
Dec 20, 2025, 1:14:29 PM (3 days ago) Dec 20
to leetcode-meetup
class Solution:
def partitionString(self, s: str) -> int:
ct = 1
seen = set()
for i in s:
if i in seen:
ct += 1
seen = set(i)
else:
seen.add(i)
return ct

Allen S.

unread,
Dec 20, 2025, 1:26:01 PM (3 days ago) Dec 20
to leetcode-meetup
func repeatedCharacter(s string) byte {
seen := [26]bool{}
for i, v := range s {
if seen[v - 'a'] {
return s[i]
}
seen[v - 'a'] = true
}
return 0
}

On Saturday, December 20, 2025 at 9:47:46 AM UTC-8 daryl...@gmail.com wrote:

Gayathri Ravichandran

unread,
Dec 20, 2025, 1:26:57 PM (3 days ago) Dec 20
to leetcod...@googlegroups.com
image.png

--
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/f760006c-426c-4057-912a-3fa224d403e1n%40googlegroups.com.

saurabh sharma

unread,
Dec 20, 2025, 1:45:01 PM (3 days ago) Dec 20
to leetcode-meetup
class Solution:
def repeatedCharacter(self, s: str) -> str:
seen = set()
for char in s:
if char in seen:
return char
seen.add(char)

On Saturday, December 20, 2025 at 9:47:46 AM UTC-8 daryl...@gmail.com wrote:

Allen S.

unread,
Dec 20, 2025, 1:48:44 PM (3 days ago) Dec 20
to leetcode-meetup
func partitionString(s string) int {
count := 1
seen := make(map[byte]bool)
for i := range s {
if seen[s[i]] {
count++
seen = make(map[byte]bool)
}
seen[s[i]] = true
}
return count
}

On Saturday, December 20, 2025 at 9:47:46 AM UTC-8 daryl...@gmail.com wrote:

saurabh sharma

unread,
Dec 20, 2025, 2:00:20 PM (3 days ago) Dec 20
to leetcode-meetup


class Solution:
def partitionString(self, s: str) -> int:
curr_substr = set()
result = 0
for char in s:
if char in curr_substr:
result += 1
curr_substr = set()
curr_substr.add(char)
else:
curr_substr.add(char)
return result+1


On Saturday, December 20, 2025 at 9:47:46 AM UTC-8 daryl...@gmail.com wrote:

Anuj Patnaik

unread,
Dec 20, 2025, 2:08:39 PM (3 days ago) Dec 20
to leetcode-meetup
class Node:
def __init__(self, key=0, value=0):
self.key = key
self.value = value
self.freq = 1
self.prev = None
self.next = None
class LinkedList:
def __init__(self):
self.head = Node()
self.tail = Node()
self.head.next = self.tail
self.tail.prev = self.head
self.size = 0
def remove(self, node):
node.prev.next = node.next
node.next.prev = node.prev
self.size -= 1

def add_front(self, node):
node.prev = self.head
node.next = self.head.next
self.head.next.prev = node
self.head.next = node
self.size += 1

class LFUCache:

def __init__(self, capacity: int):
self.capacity = capacity
self.size = 0
self.freq_to_node = dict()
self.dict_of_nums = dict()
self.min_freq = 0
def get(self, key: int) -> int:
if key not in self.dict_of_nums:
return -1
node_to_update = self.dict_of_nums[key]
freq_node_to_update = node_to_update.freq
self.freq_to_node[freq_node_to_update].remove(node_to_update)
if self.freq_to_node[freq_node_to_update].size == 0 and freq_node_to_update == self.min_freq:
self.min_freq += 1
node_to_update.freq = freq_node_to_update + 1
if node_to_update.freq not in self.freq_to_node:
self.freq_to_node[node_to_update.freq] = LinkedList()
self.freq_to_node[node_to_update.freq].add_front(node_to_update)
return node_to_update.value

def put(self, key: int, value: int) -> None:
if key in self.dict_of_nums:
node = self.dict_of_nums[key]
node.value = value
self.get(key)
return
if self.size + 1 > self.capacity:
linked_list = self.freq_to_node[self.min_freq]
node_to_remove = linked_list.tail.prev
self.freq_to_node[self.min_freq].remove(node_to_remove)
del self.dict_of_nums[node_to_remove.key]
self.size -= 1
node = Node(key, value)
self.dict_of_nums[key] = node
self.min_freq = 1

if 1 not in self.freq_to_node:
self.freq_to_node[self.min_freq] = LinkedList()
self.freq_to_node[self.min_freq].add_front(node)
self.size += 1






# Your LFUCache object will be instantiated and called as such:
# obj = LFUCache(capacity)
# param_1 = obj.get(key)
# obj.put(key,value)

Carlos Green

unread,
Dec 20, 2025, 2:22:30 PM (3 days ago) Dec 20
to leetcode-meetup
function repeatedCharacter(s: string): string {
const visited = new Set<string>()

for (let chr of s) {
if (visited.has(chr)) return chr
visited.add(chr)
}
};

Carlos Green

unread,
Dec 20, 2025, 2:55:58 PM (3 days ago) Dec 20
to leetcode-meetup
function partitionString(s: string): number {
let count: number = 1
let map = new Map<string, number>()

for (let i = 0; i < s.length; i++) {
if (map.has(s[i])) {
count++
map = new Map<string, number>()
}
map.set(s[i], i)
}

return count
};

Gayathri Ravichandran

unread,
Dec 20, 2025, 3:02:31 PM (3 days ago) Dec 20
to leetcode-meetup
class Solution:
    def partitionString(self, s: str) -> int:
        visited = [0]*26
        count = 1
        for c in s :
            lookup = ord(c) - ord('a')
            if(visited[lookup]) :
                count += 1
                visited = [0]*26
                visited[lookup] += 1
            else :
                visited[lookup] += 1
       
        return count

vinay

unread,
Dec 22, 2025, 1:14:50 AM (yesterday) Dec 22
to leetcod...@googlegroups.com
2351. First Letter to Appear Twice Easy 74.7%
time : o(n), space: o(1)
class Solution {
    public char repeatedCharacter(String s) {
        int[] arr = new int[26];

        for(char c : s.toCharArray()){
            int pos = c - 'a';
            arr[pos]++;
            if(arr[pos] > 1){
                return c;
            }
        }

        return '\0';
    }
}


2405. Optimal Partition of String Medium 78.3%
time: o(n) space: o(1)
class Solution {
    public int partitionString(String s) {
        int partitions = 1;
        int[] hash = new int[26];

        for(int i = 0; i < s.length(); i++){
            char c= s.charAt(i);
            if(hash[c - 'a'] > 0){
                partitions++;
                hash = new int[26];
            }
            hash[c - 'a']++;
           
        }

        return partitions;
    }
}

--
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.
Reply all
Reply to author
Forward
0 new messages