From 06bb4fa087faa5822f4cf38f635c14f867c475fb Mon Sep 17 00:00:00 2001 From: wazedkhan Date: Wed, 5 Nov 2025 23:36:57 +0600 Subject: [PATCH 1/4] 03: longest sub-string without repeating characters --- Go/leetcode.go | 20 ++++++++++++++++++++ Go/leetcode_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/Go/leetcode.go b/Go/leetcode.go index b3f5528..b8bab29 100644 --- a/Go/leetcode.go +++ b/Go/leetcode.go @@ -254,3 +254,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 +} diff --git a/Go/leetcode_test.go b/Go/leetcode_test.go index f5e4eda..ba62e5c 100644 --- a/Go/leetcode_test.go +++ b/Go/leetcode_test.go @@ -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) + } + } + +} From 790c180f2e427a6be6d6afa7e0e49b95d4457acc Mon Sep 17 00:00:00 2001 From: wazedkhan Date: Wed, 5 Nov 2025 23:38:34 +0600 Subject: [PATCH 2/4] 20: valid parentheses --- Go/leetcode.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Go/leetcode.go b/Go/leetcode.go index b8bab29..9075046 100644 --- a/Go/leetcode.go +++ b/Go/leetcode.go @@ -234,10 +234,7 @@ func IsValidParentheses(s string) bool { } } - if len(stack) > 0 { - return false - } - return true + return len(stack) == 0 } // 217. Contains Duplicate From 40da6773fcbf1689183ced9857a0aaa546cfd570 Mon Sep 17 00:00:00 2001 From: wazedkhan Date: Wed, 5 Nov 2025 23:56:44 +0600 Subject: [PATCH 3/4] 03: longest sub-string without repeating characters --- .../longest_substring_without_repeat.py | 16 +++++++ tests/test_leetcode_medium.py | 48 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 LeetCode/medium/longest_substring_without_repeat.py create mode 100644 tests/test_leetcode_medium.py diff --git a/LeetCode/medium/longest_substring_without_repeat.py b/LeetCode/medium/longest_substring_without_repeat.py new file mode 100644 index 0000000..78040c1 --- /dev/null +++ b/LeetCode/medium/longest_substring_without_repeat.py @@ -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 diff --git a/tests/test_leetcode_medium.py b/tests/test_leetcode_medium.py new file mode 100644 index 0000000..d2cdf2f --- /dev/null +++ b/tests/test_leetcode_medium.py @@ -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 From ec70bfc144181523765932b4484611c4c30b6d12 Mon Sep 17 00:00:00 2001 From: wazedkhan Date: Mon, 10 Nov 2025 22:01:02 +0600 Subject: [PATCH 4/4] hackos: weekly round table --- weekly_roundtable/array_hasing/nov_09_2025.py | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 weekly_roundtable/array_hasing/nov_09_2025.py diff --git a/weekly_roundtable/array_hasing/nov_09_2025.py b/weekly_roundtable/array_hasing/nov_09_2025.py new file mode 100644 index 0000000..1632272 --- /dev/null +++ b/weekly_roundtable/array_hasing/nov_09_2025.py @@ -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] + + 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]]