From 75e6a436f83390f9b6bc3f99f8f6a48a58aea630 Mon Sep 17 00:00:00 2001 From: Hyun Chan Park <126567839+Chanz82@users.noreply.github.com> Date: Thu, 23 Jul 2026 23:21:18 +0100 Subject: [PATCH 1/5] Implement maxProfit method to calculate stock profit --- best-time-to-buy-and-sell-stock/Chanz82.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 best-time-to-buy-and-sell-stock/Chanz82.py diff --git a/best-time-to-buy-and-sell-stock/Chanz82.py b/best-time-to-buy-and-sell-stock/Chanz82.py new file mode 100644 index 0000000000..c266919f09 --- /dev/null +++ b/best-time-to-buy-and-sell-stock/Chanz82.py @@ -0,0 +1,20 @@ +class Solution: + def maxProfit(self, prices: List[int]) -> int: + + # set buy, sell as index of the prices + buy = 0 + sell = 1 + + max_profit = 0 + + while sell < len(prices): # loop until we checked last prices + if prices[buy] > prices[sell]: + buy = sell # found low price for buying + else : + profit = prices[sell] - prices[buy] + max_profit = max(profit, max_profit) + + sell += 1 # next sell price + + return max_profit + From 22236c05e6fffabf45f5f795cd8050e11452731d Mon Sep 17 00:00:00 2001 From: Hyun Chan Park <126567839+Chanz82@users.noreply.github.com> Date: Thu, 23 Jul 2026 23:22:11 +0100 Subject: [PATCH 2/5] Implement groupAnagrams function in Chanz82.py --- group-anagrams/Chanz82.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 group-anagrams/Chanz82.py diff --git a/group-anagrams/Chanz82.py b/group-anagrams/Chanz82.py new file mode 100644 index 0000000000..999fbd53e2 --- /dev/null +++ b/group-anagrams/Chanz82.py @@ -0,0 +1,11 @@ + +from collections import defaultdict +class Solution: + def groupAnagrams(self, strs: List[str]) -> List[List[str]]: + + result = defaultdict(list) + for word in strs: + key = ''.join(sorted(word)) + result[key].append(word) + + return list(result.values()) From 439f551aaea3351ec8089262f7429418713ebdc2 Mon Sep 17 00:00:00 2001 From: Hyun Chan Park <126567839+Chanz82@users.noreply.github.com> Date: Thu, 23 Jul 2026 23:23:17 +0100 Subject: [PATCH 3/5] Add encode and decode methods in Solution class Implement encoding and decoding methods for a list of strings. --- encode-and-decode-strings/Chanz82.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 encode-and-decode-strings/Chanz82.py diff --git a/encode-and-decode-strings/Chanz82.py b/encode-and-decode-strings/Chanz82.py new file mode 100644 index 0000000000..e791550c5e --- /dev/null +++ b/encode-and-decode-strings/Chanz82.py @@ -0,0 +1,22 @@ +class Solution: + + def encode(self, strs: List[str]) -> str: + encoded_string = "" + + for plain_string in strs: + encoded_string = encoded_string + str(len(plain_string)) + ";" + plain_string + + #print(encoded_string) + return encoded_string + + def decode(self, s: str) -> List[str]: + decoded_str_list = [] + idx = 0 + while idx < len(s): + idx_del = s.index(";", idx) + #print(s[idx:idx_del]) + size = int(s[idx:idx_del]) + start_idx = idx_del+1 + decoded_str_list.append(s[start_idx:start_idx+size]) + idx = start_idx + size + return decoded_str_list From fa4384da84b4bf69e4a1d3b446b77cbf0fcadff0 Mon Sep 17 00:00:00 2001 From: Hyun Chan Park <126567839+Chanz82@users.noreply.github.com> Date: Thu, 23 Jul 2026 23:24:05 +0100 Subject: [PATCH 4/5] Implement Trie data structure with insert and search methods --- implement-trie-prefix-tree/Chanz82.py | 45 +++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 implement-trie-prefix-tree/Chanz82.py diff --git a/implement-trie-prefix-tree/Chanz82.py b/implement-trie-prefix-tree/Chanz82.py new file mode 100644 index 0000000000..d86520b0ec --- /dev/null +++ b/implement-trie-prefix-tree/Chanz82.py @@ -0,0 +1,45 @@ +class Trie: + + def __init__(self): + self.root_map = dict() + + def insert(self, word: str) -> None: + idx = 0 + search_map = self.root_map + while idx < len(word): + key = ord(word[idx]) + if key not in search_map: + search_map[key] = dict() + search_map = search_map[key] + idx += 1 + search_map['#'] = True + + def search(self, word: str) -> bool: + idx = 0 + search_map = self.root_map + while idx < len(word): + key = ord(word[idx]) + if key not in search_map: + return False + search_map = search_map[key] + idx += 1 + return '#' in search_map + + + def startsWith(self, prefix: str) -> bool: + idx = 0 + search_map = self.root_map + while idx < len(prefix): + key = ord(prefix[idx]) + if key not in search_map: + return False + search_map = search_map[key] + idx += 1 + return True + + +# Your Trie object will be instantiated and called as such: +# obj = Trie() +# obj.insert(word) +# param_2 = obj.search(word) +# param_3 = obj.startsWith(prefix) From 1cc533b068ee057a2240c1f54982fb8efa50d615 Mon Sep 17 00:00:00 2001 From: Hyun Chan Park <126567839+Chanz82@users.noreply.github.com> Date: Thu, 23 Jul 2026 23:24:53 +0100 Subject: [PATCH 5/5] Implement word break solution using DFS --- word-break/Chanz82.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 word-break/Chanz82.py diff --git a/word-break/Chanz82.py b/word-break/Chanz82.py new file mode 100644 index 0000000000..2c0f54cb69 --- /dev/null +++ b/word-break/Chanz82.py @@ -0,0 +1,22 @@ +class Solution: + def wordBreak(self, s: str, wordDict: List[str]) -> bool: + + visited = set() + + def dfs(start): + if start == len(s): + return True + + if start in visited: + return False + + for word in wordDict: + if s[start:start+len(word)] == word: + if dfs(start+len(word)): + return True + + visited.add(start) + return False + + return dfs(0) +