Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions Go/leetcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,7 @@ func IsValidParentheses(s string) bool {
}
}

if len(stack) > 0 {
return false
}
return true
return len(stack) == 0
}

// 217. Contains Duplicate
Expand All @@ -254,3 +251,23 @@ func ContainsDuplicate(nums []int) bool {
}
return false
}

// 3. Longest Substring Without Repeating Characters
// https://leetcode.com/problems/longest-substring-without-repeating-characters/?envType=problem-list-v2&envId=hash-table
func LengthOfLongestSubstring(s string) int {
charIndex := make(map[rune]int)
maxLen := 0
start := 0
for idx, ch := range []rune(s) {
if lastIndex, found := charIndex[ch]; found && lastIndex >= start {
start = lastIndex + 1
}
charIndex[ch] = idx

if idx-start+1 > maxLen {
maxLen = idx - start +1
}
}

return maxLen
}
27 changes: 27 additions & 0 deletions Go/leetcode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,30 @@ func Test_ContainsDuplicate(t *testing.T) {
}
}
}

// 3. Longest Substring Without Repeating Characters
// https://leetcode.com/problems/longest-substring-without-repeating-characters/?envType=problem-list-v2&envId=hash-table
func Test_LengthOfLongestSubstring(t *testing.T) {
tests := []struct {
s string
expected int
}{
{"abcabcbb", 3},
{"bbbbb", 1},
{"pwwkew", 3},
{"", 0},
{"a", 1},
{"ab", 2},
{"dvdf", 3},
{"tmmzuxt", 5},
{" ", 1},
}

for _, test := range tests {
got := LengthOfLongestSubstring(test.s)
if got != test.expected {
t.Errorf("for %s got %d but want %d", test.s, got, test.expected)
}
}

}
16 changes: 16 additions & 0 deletions LeetCode/medium/longest_substring_without_repeat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
seen_map = {}
max_len = 0
win_start = 0

for idx, value in enumerate(s):
last_index = seen_map.get(value)
if last_index is not None and last_index >= win_start:
win_start = last_index + 1

seen_map[value] = idx

max_len = max(max_len, idx - win_start + 1)

return max_len
48 changes: 48 additions & 0 deletions tests/test_leetcode_medium.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# test file for LeetCode medium problems

import pytest

# 03: Longest Substring Without Repeating Characters
# https://leetcode.com/problems/longest-substring-without-repeating-characters/?envType=problem-list-v2&envId=hash-table


@pytest.mark.parametrize(
"s, expected",
[
("abcabcbb", 3), # longest substring is "abc" with length 3
("bbbbb", 1), # longest substring is "b" with length 1
("pwwkew", 3), # longest substring is "wke" with length 3
("", 0), # empty string, longest substring is 0
("abcdef", 6), # entire string is the longest substring, length 6
("aab", 2), # longest substring is "ab", length 2
("dvdf", 3), # longest substring is "vdf", length 3
(" ", 1), # single space character, length 1
],
)
def test_length_of_longest_substring(s: str, expected: int):
from ..LeetCode.medium.longest_substring_without_repeat import Solution

solution = Solution()
assert solution.lengthOfLongestSubstring(s) == expected


# 05: Longest Palindromic Substring
# https://leetcode.com/problems/longest-palindromic-substring/?envType=problem-list-v2&envId=hash-table

# 07: Reverse Integer
# https://leetcode.com/problems/reverse-integer/?envType=problem-list-v2&envId=hash-table

# 08: String to Integer (atoi)
# https://leetcode.com/problems/string-to-integer-atoi/?envType=problem-list-v2&envId=hash-table

# 09: Palindrome Number
# https://leetcode.com/problems/palindrome-number/?envType=problem-list-v2&envId=hash-table

# 10: Regular Expression Matching
# https://leetcode.com/problems/regular-expression-matching/?envType=problem-list-v2&envId=hash-table

# 11: Container With Most Water
# https://leetcode.com/problems/container-with-most-water/?envType=problem-list-v2&envId=hash-table

# 12: Integer to Roman
# https://leetcode.com/problems/integer-to-roman/?envType=problem-list-v2&envId=hash-table
40 changes: 40 additions & 0 deletions weekly_roundtable/array_hasing/nov_09_2025.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from typing import List


class Solution:
def hasDuplicate(self, nums: List[int]) -> bool:
seen = {} # {key: valu}

for val in nums:
gg = seen.get(val)
if gg:
return True
seen[val] = 1

return False

def isAnagram(self, s: str, t: str) -> bool:
if len(s) != len(t):
return False

s_map = {}
t_map = {}

for idx in range(len(s)):
s_char = s[idx]
t_chat = t[idx]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix typo in variable name.

t_chat should be t_char for consistency and clarity.

-            t_chat = t[idx]
+            t_char = t[idx]

             s_map[s_char] = s_map.get(s_char, 0) + 1
-            t_map[t_chat] = t_map.get(t_chat, 0) + 1
+            t_map[t_char] = t_map.get(t_char, 0) + 1
🤖 Prompt for AI Agents
In weekly_roundtable/array_hasing/nov_09_2025.py around line 25, there is a typo
where the variable is named t_chat; rename it to t_char to match the intended
name and code style, update all occurrences/references in the surrounding scope
(assignments, uses, and any function parameters) to the new t_char name to avoid
NameError and keep consistency.


s_map[s_char] = s_map.get(s_char, 0) + 1
t_map[t_chat] = t_map.get(t_chat, 0) + 1

return s_map == t_map

def twoSum(self, nums: List[int], target: int) -> List[int]:
hash_map = {}
for idx in range(len(nums)):
hash_map[nums[idx]] = idx

for idx in range(len(nums)):
diff = target - nums[idx]
if diff in hash_map and hash_map[diff] != idx:
return [idx, hash_map[diff]]
Comment on lines +32 to +40
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add explicit return for the no-pair case.

The function can implicitly return None when no pair sums to the target, which violates the List[int] return type annotation.

     def twoSum(self, nums: List[int], target: int) -> List[int]:
         hash_map = {}
         for idx in range(len(nums)):
             hash_map[nums[idx]] = idx

         for idx in range(len(nums)):
             diff = target - nums[idx]
             if diff in hash_map and hash_map[diff] != idx:
                 return [idx, hash_map[diff]]
+        return []  # or raise an exception if input guarantees a solution exists
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def twoSum(self, nums: List[int], target: int) -> List[int]:
hash_map = {}
for idx in range(len(nums)):
hash_map[nums[idx]] = idx
for idx in range(len(nums)):
diff = target - nums[idx]
if diff in hash_map and hash_map[diff] != idx:
return [idx, hash_map[diff]]
def twoSum(self, nums: List[int], target: int) -> List[int]:
hash_map = {}
for idx in range(len(nums)):
hash_map[nums[idx]] = idx
for idx in range(len(nums)):
diff = target - nums[idx]
if diff in hash_map and hash_map[diff] != idx:
return [idx, hash_map[diff]]
return [] # or raise an exception if input guarantees a solution exists
🤖 Prompt for AI Agents
weekly_roundtable/array_hasing/nov_09_2025.py around lines 32-40: the twoSum
method can implicitly return None if no pair is found, violating the List[int]
annotation; add an explicit return path by raising a clear exception (e.g.,
raise ValueError("No two sum solution")) or returning an explicit empty list at
the end of the function so the return type is always List[int].

Loading