2026 July 25 Problems

61 views
Skip to first unread message

daryl...@gmail.com

unread,
Jul 25, 2026, 12:57:52 PMJul 25
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.




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,
Jul 25, 2026, 1:05:13 PMJul 25
to leetcode-meetup
class Solution:
def countGoodSubstrings(self, s: str) -> int:
if len(s) < 3:
return 0
if len(s) == 3:
if s[0] != s[1] and s[1] != s[2] and s[0] != s[2]:
return 1
else:
return 0
count = 0
for i in range(len(s) - 2):
if s[i] != s[i+1] and s[i+1] != s[i+2] and s[i] != s[i+2]:
count += 1
return count

Anuj Patnaik

unread,
Jul 25, 2026, 1:09:58 PMJul 25
to leetcode-meetup
class Solution:
def countGoodSubstrings(self, s: str) -> int:
if len(s) < 3:
return 0
count = 0
for i in range(len(s) - 2):
if s[i] != s[i+1] and s[i+1] != s[i+2] and s[i] != s[i+2]:
count += 1
return count

Carlos Green

unread,
Jul 25, 2026, 2:15:37 PMJul 25
to leetcode-meetup
/**
* @param {string} s
* @return {number}
*/
var countGoodSubstrings = function(s) {
let count = 0

for (let i = 0; i < s.length; i++) {
const slice = new Set(s.slice(i,i+3))
if (slice.size === 3) {
count++
}
}

return count
};

Jagrut

unread,
Jul 25, 2026, 2:37:45 PMJul 25
to leetcode-meetup
class Solution:
def countGoodSubstrings(self, s: str) -> int:
res = 0
k = 3
window_counts = {}
left = 0
for right, in_char in enumerate(s):
if in_char not in window_counts:
window_counts[in_char] = 0
window_counts[in_char] += 1

if right - left + 1 > k:
out_char = s[left]
window_counts[out_char] -= 1
if window_counts[out_char] == 0:
del window_counts[out_char]
left += 1

if right - left + 1 == k:
if len(window_counts) == k:
res += 1
return res

Allen S.

unread,
Jul 25, 2026, 9:25:35 PMJul 25
to leetcode-meetup
// isGood() abstracted
func countGoodSubstrings(s string) int {
    count := 0
    for i := 0; i <= len(s) - 3; i++ {
        if isGood(s[i:i+3]) {
            count++
        }
    }
    return count
}

func isGood(s string) bool {
    return s[0] != s[1] && s[1] != s[2] && s[0] != s[2]

Jagrut

unread,
Jul 25, 2026, 9:26:46 PMJul 25
to leetcode-meetup
class Solution:
def maximumSum(self, nums: List[int], m: int, l: int, r: int) -> int:
n = len(nums)
NEG_INF = float('-inf')

# pf[i] = sum of nums[0..i], inclusive
pf = [0] * n
pf[0] = nums[0]
for i in range(1, n):
pf[i] = pf[i - 1] + nums[i]

def prefix_sum(idx):
# sum of nums[0..idx-1] -- i.e. everything strictly before idx
if idx == 0:
return 0
return pf[idx - 1]

dp = [[NEG_INF] * (n + 1) for _ in range(m + 1)]
for i in range(n + 1):
dp[0][i] = 0

for j in range(1, m + 1):
window = deque() # holds (idx, g_value), g decreasing front-to-back

for i in range(n + 1):
candidate_idx = i - l
if candidate_idx >= 0 and dp[j - 1][candidate_idx] != NEG_INF:
g_value = dp[j - 1][candidate_idx] - prefix_sum(candidate_idx)
while window and window[-1][1] <= g_value:
window.pop()
window.append((candidate_idx, g_value))

while window and window[0][0] < i - r:
window.popleft()

best = dp[j][i - 1] if i >= 1 else NEG_INF
if window:
candidate_value = prefix_sum(i) + window[0][1]
if candidate_value > best:
best = candidate_value
dp[j][i] = best

return max(dp[j][n] for j in range(1, m + 1))

Gowrima Jayaramu

unread,
Jul 29, 2026, 5:17:40 PM (13 days ago) Jul 29
to leetcode-meetup
class Solution:
def countGoodSubstrings(self, s: str) -> int:
count = 0
i, j = 0, 0
substr = ""

while j < len(s):
if s[j] not in substr:
substr += s[j]

if len(substr) == 3:
count += 1
substr = ""
i += 1
j = i
continue
j += 1
else:
substr = ""
i += 1
j = i

return count

'''
Time complexity: O(n)
Space complexity: O(1)
'''
Reply all
Reply to author
Forward
0 new messages