From af8473fd5454744ca70695120aede00c5b281bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A4=80=EC=98=81?= Date: Mon, 30 Mar 2026 12:34:20 +0900 Subject: [PATCH 1/3] =?UTF-8?q?best-time-to-buy-and-sell-stock=20=ED=92=80?= =?UTF-8?q?=EC=9D=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- best-time-to-buy-and-sell-stock/junzero741.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 best-time-to-buy-and-sell-stock/junzero741.ts diff --git a/best-time-to-buy-and-sell-stock/junzero741.ts b/best-time-to-buy-and-sell-stock/junzero741.ts new file mode 100644 index 0000000000..857df55243 --- /dev/null +++ b/best-time-to-buy-and-sell-stock/junzero741.ts @@ -0,0 +1,15 @@ +// TC: O(N) +// SC: O(1) +function maxProfit(prices: number[]): number { + let maxProfit = 0 + let minPrice = Infinity + + for(const price of prices) { + maxProfit = Math.max(price - minPrice, maxProfit) + minPrice = Math.min(price, minPrice) + } + + return maxProfit + +}; + From 007f3261b796f5adb6a1c192bb914df6d1ebd8da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A4=80=EC=98=81?= Date: Tue, 31 Mar 2026 10:48:49 +0900 Subject: [PATCH 2/3] =?UTF-8?q?group-anagrams=20=ED=92=80=EC=9D=B4=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- group-anagrams/junzero741.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 group-anagrams/junzero741.ts diff --git a/group-anagrams/junzero741.ts b/group-anagrams/junzero741.ts new file mode 100644 index 0000000000..2e8292dfdb --- /dev/null +++ b/group-anagrams/junzero741.ts @@ -0,0 +1,19 @@ +// TC: O(N*KlogK) +// SC: O(N*K) +function groupAnagrams(strs: string[]): string[][] { + + const idMap = new Map(); + + for(const str of strs) { + const id = str.split("").sort().join(""); + + if(!idMap.has(id)) { + idMap.set(id, []) + } + + idMap.get(id)!.push(str) + } + + return [...idMap.values()] + +}; From 628bc9e37541319fa077a3ac7677397e59928aa7 Mon Sep 17 00:00:00 2001 From: junzero741 Date: Wed, 1 Apr 2026 21:50:12 +0900 Subject: [PATCH 3/3] =?UTF-8?q?encode-and-decode-string=20=ED=92=80?= =?UTF-8?q?=EC=9D=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- encode-and-decode-strings/junzero741.ts | 102 ++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 encode-and-decode-strings/junzero741.ts diff --git a/encode-and-decode-strings/junzero741.ts b/encode-and-decode-strings/junzero741.ts new file mode 100644 index 0000000000..6740969cc9 --- /dev/null +++ b/encode-and-decode-strings/junzero741.ts @@ -0,0 +1,102 @@ +/** + * Because the string may contain any of the 256 legal ASCII characters, your algorithm must be able to handle any character that may appear + * + * Example 1: + * Input: ["lint","code","love","you"] + * Output: ["lint","code","love","you"] + * Explanation: + * One possible encode method is: "lint:;code:;love:;you" + * + * Example 2: + * Input: ["we", "say", ":", "yes"] + * Output: ["we", "say", ":", "yes"] + * Explanation: + * One possible encode method is: "we:;say:;:::;yes" + * + * + * + * encode: + * result = "" + * loop strs, + * + * loop str, + * char to charCode + * not last str AND last char ? charCode + "*" + * not last str AND not last char ? charCode + "+" + * + * + * + * decode: + * strs = [] + * split str with "*", => ["12+79+NaN", "92+32"] + * split each element with "+", => [ ["12", "79", "NaN"], ["92", "32"] ] + * loop outer array, + * str = null + * loop inner array, + * element is "NaN" ? "" + * element is not "NaN" ? String.fromCharCode(Number(element)) + * str += + * str is not null ? strs.push(str) + * + */ + +// TC: O(N) +// SC: O(N) +class Solution { + encode (strs: string[]): string { + return strs.map((str) => { + if(str.length === 0) { + return "EMPTY" + } + const codes = []; + for(let i = 0; i < str.length; i++) { + codes.push(str.charCodeAt(i)); + } + return codes.join('+'); + }).join("*") + + } + + decode(str: string): string[] { + if(str.length === 0) { + return []; + } + + return str.split("*").map((encodedStr) => { + if(encodedStr === "EMPTY") { + return ""; + } + + return encodedStr + .split("+") + .map((code) => String.fromCharCode(Number(code))) + .join(""); + }) + } +} +const solution = new Solution(); + + + +const tc = [ + ["lint","code","love","you"], // "72+79+80+94*12+34+56+78*" + ["we", "say", ":", "yes"], + ["", "a", "", "b"], // "NaN*74*NaN*75" + [";::''',,,,.....", ".....,,,,'''::;"], +] + +function runTc(tc: string[]): boolean { + const encoded = solution.encode(tc); + const decoded = solution.decode(encoded); + if(tc.length !== decoded.length) { + return false; + } + + return tc.every((el, idx) => el === decoded[idx]); +} + +const totalTc = tc.length; +const failedTc = tc.reduce((acc, cur) => runTc(cur) ? acc : acc+1, 0); + +console.log(`success: ${totalTc-failedTc}/${totalTc}`); +