From e52cb94147174b4e420726e2d2a34ec4f360a841 Mon Sep 17 00:00:00 2001 From: Marcos Tonina Date: Sat, 24 Jan 2026 19:48:28 -0300 Subject: [PATCH 1/9] checkPermutations fix (an extra test for some border case) feat: implement checkPermutations function 01_isUnique --- .../coding/problems/01_isUnique.ts | 38 ++++++++++++++++++- .../coding/problems/02_checkPermutations.ts | 32 +++++++++++++++- .../strings/02_checkPermutations.test.ts | 4 ++ 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/technical-fundamentals/coding/problems/01_isUnique.ts b/technical-fundamentals/coding/problems/01_isUnique.ts index 07f432b1..50a0b683 100644 --- a/technical-fundamentals/coding/problems/01_isUnique.ts +++ b/technical-fundamentals/coding/problems/01_isUnique.ts @@ -3,4 +3,40 @@ // Implement an algorithm to determine if a string has all unique characters. // What if you cannot use additional data structures? -export default function isUnique(str: string): boolean {} +export default function isUnique(str: string): boolean { + + const sorted = str.split("").sort().join(""); + let prev = null; + console.log(sorted); + for(let i = 0; i < sorted.length; i++) { + if(sorted[i] === prev) return false; + prev = sorted[i]; + } + return true; + +} + +export function tsSimple(str: string){ + const map: Record = {}; + for(let i = 0; i < str.length; i++) { + if(map[str[i]]) { + return false; + } else{ + map[str[i]] = true; + } + } + return true; +} + +const pureJSSimple = function(str){ + const map = {}; + for(let i = 0; i < str.length; i++) { + console.log(map[str[i]]); + if(map[str[i]] === true) { + return false; + } else{ + map[str[i]] = true; + } + } + return true; +} diff --git a/technical-fundamentals/coding/problems/02_checkPermutations.ts b/technical-fundamentals/coding/problems/02_checkPermutations.ts index 56deb0f0..9f2d556e 100644 --- a/technical-fundamentals/coding/problems/02_checkPermutations.ts +++ b/technical-fundamentals/coding/problems/02_checkPermutations.ts @@ -2,4 +2,34 @@ // Given two strings, write a method to decide if one is a permutation of the other. -export default function checkPermutations(s1: string, s2: string): boolean {} +//O(n) -better but with more space complexity- +export default function checkPermutations(s1: string, s2: string): boolean { + const letterSet: Set = new Set(); + const letterMap: Record = {}; + + for (let i = 0; i < s1.length; i++) { + letterSet.add(s1[i]); + if(letterMap[s1[i]]) { + letterMap[s1[i]]++; + } else { + letterMap[s1[i]] = 1; + } + } + + for (let i = 0; i < s2.length; i++) { + if(!letterMap[s2[i]] || letterMap[s2[i]] === 0) { + return false; + } + if(letterMap[s2[i]] === 1) { + letterSet.delete(s2[i]); + } + letterMap[s2[i]]--; + } + + return letterSet.size === 0; +} + +//simpler solution sorting O(nlogn) +export function checkSimple(s1: string, s2: string): boolean{ + return s1.split('').sort().join('') === s2.split('').sort().join(''); +} \ No newline at end of file diff --git a/technical-fundamentals/coding/problems/__tests__/strings/02_checkPermutations.test.ts b/technical-fundamentals/coding/problems/__tests__/strings/02_checkPermutations.test.ts index cfac3212..e67d246c 100644 --- a/technical-fundamentals/coding/problems/__tests__/strings/02_checkPermutations.test.ts +++ b/technical-fundamentals/coding/problems/__tests__/strings/02_checkPermutations.test.ts @@ -28,4 +28,8 @@ describe('02 - checkPermutation', () =>{ test('Returns false for long strings with different characters', () =>{ expect(checkPermutations('a'.repeat(1000),'b'.repeat(1000))).toEqual(false); }); + + test('Returns false for non-permutations with subgroup in the second one -it prevents uncomplete solutions-', () =>{ + expect(checkPermutations('abc','bc')).toEqual(false); + }); }) From a0a03eee43c18e69e18362423776e812b9f29c9d Mon Sep 17 00:00:00 2001 From: Marcos Tonina Date: Tue, 27 Jan 2026 19:50:40 -0300 Subject: [PATCH 2/9] Removing console.log() --- technical-fundamentals/coding/problems/01_isUnique.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/technical-fundamentals/coding/problems/01_isUnique.ts b/technical-fundamentals/coding/problems/01_isUnique.ts index 50a0b683..6bceec1e 100644 --- a/technical-fundamentals/coding/problems/01_isUnique.ts +++ b/technical-fundamentals/coding/problems/01_isUnique.ts @@ -7,7 +7,6 @@ export default function isUnique(str: string): boolean { const sorted = str.split("").sort().join(""); let prev = null; - console.log(sorted); for(let i = 0; i < sorted.length; i++) { if(sorted[i] === prev) return false; prev = sorted[i]; From 7b2cb10c6b74f141d18c47e3e769f7182e0cc08b Mon Sep 17 00:00:00 2001 From: Marcos Tonina Date: Wed, 28 Jan 2026 10:44:50 -0300 Subject: [PATCH 3/9] Fixing scenario 4 in O(n) --- .../problems/04_palindromePermutation.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/technical-fundamentals/coding/problems/04_palindromePermutation.ts b/technical-fundamentals/coding/problems/04_palindromePermutation.ts index d80c9217..fe550bf7 100644 --- a/technical-fundamentals/coding/problems/04_palindromePermutation.ts +++ b/technical-fundamentals/coding/problems/04_palindromePermutation.ts @@ -11,4 +11,29 @@ export default function palindromePermutation (str: string): boolean { + //worst case time complexity = O(2n) -> O(n) + + let charMap: Map = new Map(); + for (let i = 0; i < str.length; i++) { + if(str[i] === ' ') continue; + const currChar = str[i].toLowerCase(); + if(charMap.has(currChar)){ + charMap.set(currChar, charMap.get(currChar) + 1); + } else { + charMap.set(currChar, 1); + } + } + + let oddValues: number = 0; + + for(const [_, number] of charMap){ + if(number % 2 !== 0 && oddValues > 0) { + return false; + } else if(number % 2 !== 0){ + oddValues++; + } + } + + return true; + } \ No newline at end of file From c643fec22ea500ce17a05eae9fa49cde5ff311d7 Mon Sep 17 00:00:00 2001 From: Marcos Tonina Date: Wed, 28 Jan 2026 21:16:57 -0300 Subject: [PATCH 4/9] Fixing scenario 5 in O(n) --- .../coding/problems/05_oneAway.ts | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/technical-fundamentals/coding/problems/05_oneAway.ts b/technical-fundamentals/coding/problems/05_oneAway.ts index 79c9a12d..ad31ae84 100644 --- a/technical-fundamentals/coding/problems/05_oneAway.ts +++ b/technical-fundamentals/coding/problems/05_oneAway.ts @@ -5,5 +5,28 @@ // Given two strings, write a function to check if they are one edit (or zero edits) away. export default function isOneAway(str1: string, str2: string): boolean { - + + if(str1.length > str2.length + 2 || str1.length < str2.length - 2) return false; + if(str1 === str2) return true; + + for(let i = 0; i < str1.length; i++){ + if(str1[i] !== str2[i]){ + return equalsWithDelete(str1.substring(i), str2.substring(i)) || + equalsWithInsert(str1.substring(i), str2.substring(i)) || + equalsWithReplace(str1.substring(i), str2.substring(i)); + } + } + + return true; + +} + +export function equalsWithDelete(str1: string, str2: string): boolean { + return str1.substring(1) === str2 || str1 === str2.substring(1); +} +export function equalsWithInsert(str1: string, str2: string): boolean { + return str2[0] + str1 === str2 || str1[0] + str2 === str1; +} +export function equalsWithReplace(str1: string, str2: string): boolean { + return str2[0] + str1.substring(1) === str2 || str1[0] + str2.substring(1) === str1; } From b435805f3d8a9cff774e3f8565b3971305514e29 Mon Sep 17 00:00:00 2001 From: Marcos Tonina Date: Wed, 28 Jan 2026 21:30:25 -0300 Subject: [PATCH 5/9] Fixing scenario 6 in O(n) --- .../coding/problems/06_stringCompression.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/technical-fundamentals/coding/problems/06_stringCompression.ts b/technical-fundamentals/coding/problems/06_stringCompression.ts index 525ce40d..996d9d1c 100644 --- a/technical-fundamentals/coding/problems/06_stringCompression.ts +++ b/technical-fundamentals/coding/problems/06_stringCompression.ts @@ -7,5 +7,22 @@ // You can assume the string has only uppercase and lowercase letters (a - z). export default function stringCompression (str: string) : string { + let counter: number = 0; + let prev: string = ''; + let output: string = ''; + for(let i: number = 0; i < str.length; i++){ + if(str[i] !== prev){ + if(prev != ''){ + output += prev + counter.toString(); + counter = 0; + } + prev = str[i]; + } + counter++; + } + + output += prev + counter.toString(); + + return output.length < str.length ? output : str; } \ No newline at end of file From 8aef5912c3f5ec1d256d86aa20d8cae441756484 Mon Sep 17 00:00:00 2001 From: Marcos Tonina Date: Thu, 29 Jan 2026 17:19:43 -0300 Subject: [PATCH 6/9] Fixing scenario 7 in O(n) --- .../coding/problems/07_rotateMatrix.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/technical-fundamentals/coding/problems/07_rotateMatrix.ts b/technical-fundamentals/coding/problems/07_rotateMatrix.ts index 875d0841..9f47f1cc 100644 --- a/technical-fundamentals/coding/problems/07_rotateMatrix.ts +++ b/technical-fundamentals/coding/problems/07_rotateMatrix.ts @@ -7,4 +7,16 @@ type Matrix = number[][] export default function rotateMatrix (matrix: Matrix) { -} \ No newline at end of file + for(let i = 0; i < matrix.length; i++){ + for(let j = i; j < matrix.length; j++){ + const aux = matrix[i][j]; + matrix[i][j] = matrix[j][i]; + matrix[j][i] = aux; + } + } + + for(let i = 0; i < matrix.length; i++){ + matrix[i].reverse(); + } + +} From 06b1d72ed3d559078f4fd671921fa38263b1b623 Mon Sep 17 00:00:00 2001 From: Marcos Tonina Date: Thu, 29 Jan 2026 18:31:05 -0300 Subject: [PATCH 7/9] Fixing scenario 8 in O(n) --- .../coding/problems/08_zeroMatrix.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/technical-fundamentals/coding/problems/08_zeroMatrix.ts b/technical-fundamentals/coding/problems/08_zeroMatrix.ts index 5bf6941d..5d4d007f 100644 --- a/technical-fundamentals/coding/problems/08_zeroMatrix.ts +++ b/technical-fundamentals/coding/problems/08_zeroMatrix.ts @@ -6,4 +6,29 @@ type Matrix = number[][] export default function zeroMatrix (matrix: Matrix) { + let setRow: Set = new Set(); + let setCol: Set = new Set(); + for(let i = 0; i < matrix[0].length; i++){ + for(let j= 0; j < matrix.length; j++){ + if(matrix[i][j] === 0 && !setRow.has(i) && !setCol.has(j)){ + fillRow(i, matrix[0].length, matrix); + fillCol(j, matrix.length, matrix); + setRow.add(i); + setCol.add(j); + } + } + } + +} + +export function fillCol(col:number, mlength: number, matrix: Matrix){ + for(let i = 0; i < mlength; i++){ + matrix[i][col] = 0; + } +} + +export function fillRow(row:number, mlength: number, matrix: Matrix){ + for(let j = 0; j < mlength; j++){ + matrix[row][j] = 0; + } } \ No newline at end of file From 3d8b7fecdf0df1e4c32491516ab5c60328385d29 Mon Sep 17 00:00:00 2001 From: Marcos Tonina Date: Thu, 29 Jan 2026 18:50:18 -0300 Subject: [PATCH 8/9] Fixing scenario 9 in O(n) --- .../coding/problems/09_stringRotation.ts | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/technical-fundamentals/coding/problems/09_stringRotation.ts b/technical-fundamentals/coding/problems/09_stringRotation.ts index afc900e0..385fbdf6 100644 --- a/technical-fundamentals/coding/problems/09_stringRotation.ts +++ b/technical-fundamentals/coding/problems/09_stringRotation.ts @@ -6,4 +6,24 @@ import { isSubstring } from "./__utils__/strings" // Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 using only one call to isSubstring. // [e.g., "waterbottle" is a rotation of 'erbottlewat") -export default function stringRotation(s1: string, s2: string): boolean {} +export default function stringRotation(s1: string, s2: string): boolean { + + if(s1.length != s2.length) return false; + + let stringEnd = ""; + + for(let i = 0; i < s1.length; i++){ + if(s2[i] !== s1[0]){ + stringEnd += s2[i]; + } else { + if(s2.substring(i) + stringEnd === s1){ + return true; + } else { + stringEnd += s2[i]; + } + } + } + + return false; + +} From b708e79569faefa212ccbca2565f5e0134a7afa5 Mon Sep 17 00:00:00 2001 From: Marcos Tonina Date: Thu, 29 Jan 2026 20:44:06 -0300 Subject: [PATCH 9/9] Fixing scenario 3 in O(n) in place using arrays --- .../coding/problems/03_urlify.ts | 25 ++++++++++++++++++- .../__tests__/strings/03_URLify.test.ts | 12 ++++----- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/technical-fundamentals/coding/problems/03_urlify.ts b/technical-fundamentals/coding/problems/03_urlify.ts index ca989b83..e7f75751 100644 --- a/technical-fundamentals/coding/problems/03_urlify.ts +++ b/technical-fundamentals/coding/problems/03_urlify.ts @@ -4,6 +4,29 @@ // You may assume that the string has sufficient space at the end to hold the additional characters, // and that you are given the "true" length of the string. -export default function URLify (s1 : string): string { +export default function URLify (s1 : string[]): string[] { + + let next = s1[s1.length - 1]; + let index: number = s1.length - 1; + while(next === ' '){ + index--; + next = s1[index]; + } + + let pointer = s1.length - 1; + + for(let i = index; i >= 0; i--){ + if(s1[i] !== ' '){ + s1[pointer] = s1[i]; + pointer--; + } else { + s1[pointer] = '0'; + s1[pointer - 1] = '2'; + s1[pointer - 2] = '%'; + pointer -= 3; + } + } + + return s1; } \ No newline at end of file diff --git a/technical-fundamentals/coding/problems/__tests__/strings/03_URLify.test.ts b/technical-fundamentals/coding/problems/__tests__/strings/03_URLify.test.ts index 5ec8a26d..ba9cc834 100644 --- a/technical-fundamentals/coding/problems/__tests__/strings/03_URLify.test.ts +++ b/technical-fundamentals/coding/problems/__tests__/strings/03_URLify.test.ts @@ -2,11 +2,11 @@ import URLify from "../../03_urlify"; describe('03 - URLify', () =>{ test("Replaces spaces in a string with '%20'", () =>{ - expect(URLify('ab c')).toEqual('ab%20c'); + expect(URLify([...'ab c '])).toEqual([...'ab%20c']); }); test("Handles leading and trailing spaces", () =>{ - expect(URLify(' ab c ')).toEqual('%20%20ab%20c%20%20'); + expect(URLify([...' ab c '])).toEqual([...'%20%20ab%20c']); }); test("Returns empty string when input is empty", () =>{ @@ -14,18 +14,18 @@ describe('03 - URLify', () =>{ }); test("Doesn't modify string without spaces", () =>{ - expect(URLify('abc')).toEqual('abc'); + expect(URLify([...'abc'])).toEqual([...'abc']); }); test("Handles multiple consecutive spaces", () =>{ - expect(URLify('a b c')).toEqual('a%20%20b%20%20%20c'); + expect(URLify([...'a b c '])).toEqual([...'a%20%20b%20%20%20c']); }); test("Handles special characters", () =>{ - expect(URLify('a b!c')).toEqual('a%20b!c'); + expect(URLify([...'a b!c '])).toEqual([...'a%20b!c']); }); test("Mr 3ohn Smith", () =>{ - expect(URLify('Mr 3ohn Smith')).toEqual('Mr%203ohn%20Smith'); + expect(URLify([...'Mr 3ohn Smith '])).toEqual([...'Mr%203ohn%20Smith']); }); });