2026 May 2 Problems

43 views
Skip to first unread message

daryl...@gmail.com

unread,
May 2, 2026, 12:42:00 PM (9 days ago) May 2
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.


Carry over problems from last week:

3853. Merge Close Characters Medium 54.6%


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

Bhupathi Kakarlapudi

unread,
May 2, 2026, 1:55:25 PM (9 days ago) May 2
to leetcod...@googlegroups.com
class Solution:
def balancedStringSplit(self, s: str) -> int:
balance:int = 0
num_of_balance_strings:int = 0
for ch in s:
if ch == 'L':
balance += 1
else:
balance -= 1

if balance == 0:
num_of_balance_strings += 1

return num_of_balance_strings

--
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/5e7665e2-5a82-4b3f-9adf-4cb17b22b54dn%40googlegroups.com.

Allen S.

unread,
May 2, 2026, 2:20:05 PM (9 days ago) May 2
to leetcode-meetup
func balancedStringSplit(s string) int {
balance := 0
count := 0
for _, v := range s {
if v == 'L' {
balance++
} else {
balance--
}
if balance == 0 {
count++
}
}
return count
}

Allen S.

unread,
May 2, 2026, 2:20:19 PM (9 days ago) May 2
to leetcode-meetup
func mergeCharacters(s string, k int) string {
latestIndex := map[byte]int{}
keyOffset := map[byte]int{}
res := []byte{}
for i := range s {
// close ?
if j, ok := latestIndex[s[i]]; ok && i - j - keyOffset[s[i]] <= k { // yes
for key := range keyOffset {
keyOffset[key]++
}
} else { // not close
res = append(res, s[i])
latestIndex[s[i]] = i
keyOffset[s[i]] = 0
}
}
return string(res)
}

Anuj Patnaik

unread,
May 2, 2026, 2:22:46 PM (9 days ago) May 2
to leetcode-meetup
class Solution:
def balancedStringSplit(self, s: str) -> int:
balanced_str = 0
ct = 0
for i in s:
if i == 'R':
balanced_str -= 1
else:
balanced_str += 1
if balanced_str == 0:
ct += 1
return ct

Bhupathi Kakarlapudi

unread,
May 2, 2026, 2:32:14 PM (9 days ago) May 2
to leetcod...@googlegroups.com
class Solution:
def mergeCharacters(self, s: str, k: int) -> str:
arr = list(s)
while True:
merged = False
n = len(arr)
for i in range(n):
for j in range(i + 1, min(i+1+k,n)):
if arr[i] == arr[j]:
arr.pop(j) # right merges into left
merged = True
break
if merged:
break
if not merged:
break
return "".join(arr)

Rudy W

unread,
May 2, 2026, 7:26:39 PM (9 days ago) May 2
to leetcod...@googlegroups.com
class Solution:
def balancedStringSplit(self, s: str) -> int:
# intuition: consider char 'L' equal to integer -1 value
# and char 'R' -> integer +1
# since s is a balanced string, that means the number of 'L' chars is equal to the number of 'R' chars
# that also means the total value of string s is 0

# here create a hash map of char 'L' and char 'R', assign both to -1 and 1 respectively
hash = {'L': -1, 'R': 1}
max = 0
current_total = 0
for c in s:
current_total += hash[c]

# when the current total is equal to 0
# that is when the substring has an equal quantity of 'L' and 'R' chars
if current_total == 0:
max += 1
return max



class Solution:
def mergeCharacters(self, s: str, k: int) -> str:

# intuition: store the up to date/current index in the hash map
# need to keep track of number of deletion/merge
# hash map will store the char index
hash = defaultdict(int)

new_str = ''

# keep track deletion count so that the char index is up to date to the new_str index
del_count = 0

for i, char in enumerate(s):
# print(f'new_str={new_str}, del_count={del_count}')

if char not in hash:
hash[char] = i - del_count
new_str += char
elif char in hash:
if i - hash[char] - del_count > k:
hash[char] = i - del_count
new_str += char

else:
# remove char -> don't write to new_str
del_count += 1

return new_str


Reply all
Reply to author
Forward
0 new messages