From 7f8007319b44bd206a1160a424a9cef74a97dcad Mon Sep 17 00:00:00 2001 From: dolphinflow86 Date: Sun, 28 Jun 2026 23:33:19 +0900 Subject: [PATCH 1/7] valid anagram solution 1 --- valid-anagram/dolphinflow86.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 valid-anagram/dolphinflow86.py diff --git a/valid-anagram/dolphinflow86.py b/valid-anagram/dolphinflow86.py new file mode 100644 index 0000000000..28f71daf12 --- /dev/null +++ b/valid-anagram/dolphinflow86.py @@ -0,0 +1,6 @@ +# 1) Sort input strings and check if those are the same. +# TC: O(NlogN) where N is the size of string s and t due to sorting +# SC: O(N) where N is the length of string s and t to store sorted list. +class Solution: + def isAnagram(self, s: str, t: str) -> bool: + return sorted(s) == sorted(t) From d5a06a52c457f3cf0099bfcf89f60aca72f3863b Mon Sep 17 00:00:00 2001 From: dolphinflow86 Date: Mon, 29 Jun 2026 22:02:49 +0900 Subject: [PATCH 2/7] valid anagram optimized solution --- valid-anagram/dolphinflow86.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/valid-anagram/dolphinflow86.py b/valid-anagram/dolphinflow86.py index 28f71daf12..fbecb61bd4 100644 --- a/valid-anagram/dolphinflow86.py +++ b/valid-anagram/dolphinflow86.py @@ -4,3 +4,22 @@ class Solution: def isAnagram(self, s: str, t: str) -> bool: return sorted(s) == sorted(t) + +# 2) Using dict to store count of the first string and decrease back to see if there's negative count. +# TC: O(N + M) where N is the length of s and M is the length of t. +# SC: O(N + M) where N is the length of s and M is the length of t. +class Solution: + def isAnagram(self, s: str, t: str) -> bool: + if len(s) != len(t): return False + + char_map: Dict[str, int] = {} + for ch in s: + char_map[ch] = char_map.get(ch, 0) + 1 + + for ch in t: + if ch not in char_map or char_map[ch] == 0: + return False + + char_map[ch] -= 1 + + return True From 4ddaf987f98762e94b17ff906835269a54a4ef90 Mon Sep 17 00:00:00 2001 From: dolphinflow86 Date: Mon, 29 Jun 2026 22:17:19 +0900 Subject: [PATCH 3/7] climbing stairs solution 1 --- climbing-stairs/dolphinflow86.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 climbing-stairs/dolphinflow86.py diff --git a/climbing-stairs/dolphinflow86.py b/climbing-stairs/dolphinflow86.py new file mode 100644 index 0000000000..8449501344 --- /dev/null +++ b/climbing-stairs/dolphinflow86.py @@ -0,0 +1,20 @@ +# 1) Recursion with memoization. +# TC: O(N) where N is the given natural number. +# SC: O(N) where N is the given natural number. +class Solution: + def climb_rec(self, n: int, step: int, memo: Dict[int, int]): + if step > n: return 0 + if step in memo: return memo[step] + if step == n: return 1 + + first_way = self.climb_rec(n, step + 1, memo) + second_way = self.climb_rec(n, step + 2, memo) + memo[step] = first_way + second_way + return memo[step] + + + def climbStairs(self, n: int) -> int: + if n == 1: return 1 + + memo = {} + return self.climb_rec(n, 1, memo) + self.climb_rec(n, 2, memo) From ae0679bf5ef9178971cef400ab392debfb28d80f Mon Sep 17 00:00:00 2001 From: dolphinflow86 Date: Tue, 30 Jun 2026 16:37:31 +0900 Subject: [PATCH 4/7] product of array except self solution --- product-of-array-except-self/dolphinflow86.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 product-of-array-except-self/dolphinflow86.py diff --git a/product-of-array-except-self/dolphinflow86.py b/product-of-array-except-self/dolphinflow86.py new file mode 100644 index 0000000000..79455610a6 --- /dev/null +++ b/product-of-array-except-self/dolphinflow86.py @@ -0,0 +1,20 @@ +# 1) Without using division operator and need to meet linear time complexity, +# calculate left accumulated product and calculate right accumulated product except iself and then +# product of left and right to get the result. +# TC: O(N) where N is the length of nums +# SC: O(N) where N is the length of nums +class Solution: + def productExceptSelf(self, nums: List[int]) -> List[int]: + n = len(nums) + answer = [1] * n + acc = 1 + for i in range(1, n): + acc *= nums[i-1] + answer[i] = acc + + acc = 1 + for i in range(n-2, -1, -1): + acc *= nums[i+1] + answer[i] *= acc + + return answer From b85bcd82e934502f88438f25f7aaf58a93a996dc Mon Sep 17 00:00:00 2001 From: dolphinflow86 Date: Wed, 1 Jul 2026 19:04:52 +0900 Subject: [PATCH 5/7] 3 sum solution --- 3sum/dolphinflow86.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 3sum/dolphinflow86.py diff --git a/3sum/dolphinflow86.py b/3sum/dolphinflow86.py new file mode 100644 index 0000000000..44de609f17 --- /dev/null +++ b/3sum/dolphinflow86.py @@ -0,0 +1,21 @@ +# 1) Fix one element first, and then treat others as two-sum problem. Use set to get rid of duplicate combination. +# TC: O(N^2) where N is the length of nums. +# SC: O(N) where N is the length of nums. +class Solution: + def threeSum(self, nums: list[int]) -> list[list[int]]: + answer: Set[tuple[int,int,int]] = set() + n = len(nums) + nums.sort() + + for i in range(n-2): + if i > 0 and nums[i] == nums[i-1]: continue + + target = -nums[i] + nums_map: Dict[int, int] = {} + for j in range(i + 1, n): + comp = target - nums[j] + if comp in nums_map: + answer.add((nums[i], comp, nums[j])) + nums_map[nums[j]] = j + + return [list(triplet) for triplet in answer] From ac7e3f3c2d076259ab431db49017659022cc2ae5 Mon Sep 17 00:00:00 2001 From: dolphinflow86 Date: Sat, 4 Jul 2026 00:43:33 +0900 Subject: [PATCH 6/7] validate binary search tree solution --- validate-binary-search-tree/dolphinflow86.py | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 validate-binary-search-tree/dolphinflow86.py diff --git a/validate-binary-search-tree/dolphinflow86.py b/validate-binary-search-tree/dolphinflow86.py new file mode 100644 index 0000000000..0ec6163111 --- /dev/null +++ b/validate-binary-search-tree/dolphinflow86.py @@ -0,0 +1,22 @@ +# 1) Validate the BST using min and max values for each node. +# TC: O(N) where N is the number of nodes in the BST +# SC: O(H) where H is the height of the BST + +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def solve(self, node: Optional[TreeNode], min: int, max: int) -> bool: + if node == None: return True + + if node.val <= min or node.val >= max: return False + + left = self.solve(node.left, min, node.val) + right = self.solve(node.right, node.val, max) + return left and right + + def isValidBST(self, root: Optional[TreeNode]) -> bool: + return self.solve(root, float('-inf'), float('inf')) \ No newline at end of file From 966119b0ca5026143145881616fbe5263c067762 Mon Sep 17 00:00:00 2001 From: dolphinflow86 Date: Sat, 4 Jul 2026 00:47:03 +0900 Subject: [PATCH 7/7] add empty line --- validate-binary-search-tree/dolphinflow86.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validate-binary-search-tree/dolphinflow86.py b/validate-binary-search-tree/dolphinflow86.py index 0ec6163111..d7652361c2 100644 --- a/validate-binary-search-tree/dolphinflow86.py +++ b/validate-binary-search-tree/dolphinflow86.py @@ -19,4 +19,4 @@ def solve(self, node: Optional[TreeNode], min: int, max: int) -> bool: return left and right def isValidBST(self, root: Optional[TreeNode]) -> bool: - return self.solve(root, float('-inf'), float('inf')) \ No newline at end of file + return self.solve(root, float('-inf'), float('inf'))