From ec64a372271eac8d3fdc771b518a1dd8e4f1dbc2 Mon Sep 17 00:00:00 2001 From: dolphinflow86 <19372057+dolphinflow86@users.noreply.github.com> Date: Thu, 13 Aug 2026 01:29:27 +0000 Subject: [PATCH 1/5] reverse bits solution --- reverse-bits/dolphinflow86.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 reverse-bits/dolphinflow86.py diff --git a/reverse-bits/dolphinflow86.py b/reverse-bits/dolphinflow86.py new file mode 100644 index 0000000000..de98ccd19c --- /dev/null +++ b/reverse-bits/dolphinflow86.py @@ -0,0 +1,11 @@ +# 1) Iterate 32 times, getting the last bit of n and putting it to res using bitwise operators. +# TC: O(1) +# SC: O(1) +class Solution: + def reverseBits(self, n: int) -> int: + res = 0 + for _ in range(32): + bit = n & 1 + res = (res << 1) | bit + n >>= 1 + return res From 3ae25589957658399984781ffc7703b4f9882370 Mon Sep 17 00:00:00 2001 From: dolphinflow86 Date: Fri, 14 Aug 2026 23:07:36 +0900 Subject: [PATCH 2/5] clone graph solution --- clone-graph/dolphinflow86.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 clone-graph/dolphinflow86.py diff --git a/clone-graph/dolphinflow86.py b/clone-graph/dolphinflow86.py new file mode 100644 index 0000000000..3478ed1900 --- /dev/null +++ b/clone-graph/dolphinflow86.py @@ -0,0 +1,36 @@ +# N is the number of nodes, and E is the number of edges. +# TC: O(N + E) - visits each node and edge once +# SC: O(N) - uses a hash map for cloned nodes and the recursion stack + +""" +# Definition for a Node. +class Node: + def __init__(self, val = 0, neighbors = None): + self.val = val + self.neighbors = neighbors if neighbors is not None else [] +""" + +from typing import Optional + + +class Solution: + + def cloneGraph(self, node: Optional['Node']) -> Optional['Node']: + if not node: + return None + + cloned = {} + + def dfs(curr): + if curr in cloned: + return cloned[curr] + + copy = Node(curr.val) + cloned[curr] = copy + + for neighbor in curr.neighbors: + copy.neighbors.append(dfs(neighbor)) + + return copy + + return dfs(node) From 4a7a737ed809b1cae782086c1a828a7d15452270 Mon Sep 17 00:00:00 2001 From: dolphinflow86 Date: Fri, 14 Aug 2026 23:07:37 +0900 Subject: [PATCH 3/5] longest common subsequence solution --- longest-common-subsequence/dolphinflow86.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 longest-common-subsequence/dolphinflow86.py diff --git a/longest-common-subsequence/dolphinflow86.py b/longest-common-subsequence/dolphinflow86.py new file mode 100644 index 0000000000..f35a2fcd87 --- /dev/null +++ b/longest-common-subsequence/dolphinflow86.py @@ -0,0 +1,17 @@ +# M is the length of text1, and N is the length of text2. +# TC: O(M * N) - fills a 2D DP table of size (M+1) x (N+1) +# SC: O(M * N) - uses a 2D array to store intermediate DP values +class Solution: + + def longestCommonSubsequence(self, text1: str, text2: str) -> int: + m, n = len(text1), len(text2) + dp = [[0] * (n + 1) for _ in range(m + 1)] + + for i in range(1, m + 1): + for j in range(1, n + 1): + if text1[i - 1] == text2[j - 1]: + dp[i][j] = dp[i - 1][j - 1] + 1 + else: + dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + + return dp[m][n] From 0c5f1a466d739ba723c3e157ecf78b53f31b85df Mon Sep 17 00:00:00 2001 From: dolphinflow86 Date: Fri, 14 Aug 2026 23:07:37 +0900 Subject: [PATCH 4/5] longest repeating character replacement solution --- .../dolphinflow86.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 longest-repeating-character-replacement/dolphinflow86.py diff --git a/longest-repeating-character-replacement/dolphinflow86.py b/longest-repeating-character-replacement/dolphinflow86.py new file mode 100644 index 0000000000..55c90275d4 --- /dev/null +++ b/longest-repeating-character-replacement/dolphinflow86.py @@ -0,0 +1,22 @@ +# N is the length of string s, and K is the allowed replacements. +# TC: O(N) - single pass with sliding window +# SC: O(1) - hash table stores at most 26 uppercase English letters +class Solution: + + def characterReplacement(self, s: str, k: int) -> int: + count = {} + max_freq = 0 + left = 0 + max_length = 0 + + for right in range(len(s)): + count[s[right]] = count.get(s[right], 0) + 1 + max_freq = max(max_freq, count[s[right]]) + + while (right - left + 1) - max_freq > k: + count[s[left]] -= 1 + left += 1 + + max_length = max(max_length, right - left + 1) + + return max_length From c48a7a07937f819e4a8c655e6dc00430c3434d71 Mon Sep 17 00:00:00 2001 From: dolphinflow86 Date: Fri, 14 Aug 2026 23:07:37 +0900 Subject: [PATCH 5/5] palindromic substrings solution --- palindromic-substrings/dolphinflow86.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 palindromic-substrings/dolphinflow86.py diff --git a/palindromic-substrings/dolphinflow86.py b/palindromic-substrings/dolphinflow86.py new file mode 100644 index 0000000000..97d4771bbe --- /dev/null +++ b/palindromic-substrings/dolphinflow86.py @@ -0,0 +1,23 @@ +# N is the length of string s. +# TC: O(N^2) - expands around each center (2N - 1 possible centers) +# SC: O(1) - uses only constant extra space +class Solution: + + def expand_around_center(self, s: str, left: int, right: int) -> int: + sub_count = 0 + + while left >= 0 and right < len(s) and s[left] == s[right]: + sub_count += 1 + left -= 1 + right += 1 + + return sub_count + + def countSubstrings(self, s: str) -> int: + count = 0 + + for i in range(len(s)): + count += self.expand_around_center(s, i, i) + count += self.expand_around_center(s, i, i + 1) + + return count