From e52cb94147174b4e420726e2d2a34ec4f360a841 Mon Sep 17 00:00:00 2001 From: Marcos Tonina Date: Sat, 24 Jan 2026 19:48:28 -0300 Subject: [PATCH 01/20] 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 02/20] 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 03/20] 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 04/20] 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 05/20] 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 06/20] 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 07/20] 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 08/20] 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 09/20] 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']); }); }); From f4c752f68008acfcddeea138d0d8313b6ed73d5a Mon Sep 17 00:00:00 2001 From: Marcos Tonina Date: Sat, 7 Feb 2026 14:51:22 -0300 Subject: [PATCH 10/20] Fixing scenario 11 with two approaches --- .../coding/problems/10_LinkedList.ts | 65 ++++++++++++++----- .../coding/problems/11_removeDups.ts | 53 +++++++++++++-- .../__tests__/lists/11_removeDups.test.ts | 27 ++++++++ 3 files changed, 125 insertions(+), 20 deletions(-) diff --git a/technical-fundamentals/coding/problems/10_LinkedList.ts b/technical-fundamentals/coding/problems/10_LinkedList.ts index a88e026f..3e39f282 100644 --- a/technical-fundamentals/coding/problems/10_LinkedList.ts +++ b/technical-fundamentals/coding/problems/10_LinkedList.ts @@ -3,29 +3,62 @@ // Create the data structure with the corresponding initial functions: export type Node = { - next?: Node | undefined; - value: T; + next?: Node | undefined; + value: T; }; export class LinkedList { - head: Node | undefined; - tail: Node | undefined; + head: Node | undefined; + tail: Node | undefined; - constructor(head?: Node) {} + constructor(head?: Node) { + this.head = head; + this.tail = head; + } - push(value: T) {} - filter() {} - visit() {} - remove() {} - merge() {} - print() {} + push(value: T) { + let newNode: Node = {value: value}; + if (this.tail) { + this.tail.next = newNode; + this.tail = newNode; + } else { + this.head = newNode; + this.tail = this.head; + } + } - // extra + filter(fn: (node: Node) => boolean): LinkedList { + const result = new LinkedList(); + if (!this.head) return this; + let p: Node | undefined = this.head; + while (p) { + if (fn(p)) { + result.push(p.value); + } + p = p.next; + } - //find(): Node {} - //get(index: number): Node {} - //iterator(): LinkedListIterator {} - length: number; + return result; + } + + visit() { + } + + remove() { + } + + merge() { + } + + print() { + } + + // extra + + //find(): Node {} + //get(index: number): Node {} + //iterator(): LinkedListIterator {} + length: number; } const list = new LinkedList(); diff --git a/technical-fundamentals/coding/problems/11_removeDups.ts b/technical-fundamentals/coding/problems/11_removeDups.ts index 822defc6..36c7a20c 100644 --- a/technical-fundamentals/coding/problems/11_removeDups.ts +++ b/technical-fundamentals/coding/problems/11_removeDups.ts @@ -5,11 +5,56 @@ // // 1 -> 2 -> 2-> 2 -> 4 -import { LinkedList } from "./10_LinkedList"; +import {LinkedList} from "./10_LinkedList"; export type Node = { - value: T; - next?: Node; + value: T; + next?: Node; }; -export default function removeDups(head?: Node): Node | undefined {} +export default function removeDups(head?: Node): Node | undefined { + // no extra structures, just pointers + // from beginning to current position -> no dups + // each one iterates from start and if it's repeated -> jump + + let p = head; + outerWhile: while(p){ + let q = head; //q: from start to current + while(q && (q !== p)){ + if(p.next && q.value === p.next.value){ + p.next = p.next.next; + continue outerWhile; + } + q = q.next; + } + + //initial case or repetition + if(q === p && p.next && q.value === p.next.value){ + p.next = p.next.next; + continue; + } + + p = p.next; + } + + return head; + +} + +export function removeDups2(head?: Node): Node | undefined { + + const lList: LinkedList = new LinkedList(head); + const mySet: Set = new Set(); + + const ret: LinkedList = lList.filter((node: Node) => { + if (mySet.has(node.value)) { + return false; + } else { + mySet.add(node.value); + return true; + } + }); + + return ret.head; + +} diff --git a/technical-fundamentals/coding/problems/__tests__/lists/11_removeDups.test.ts b/technical-fundamentals/coding/problems/__tests__/lists/11_removeDups.test.ts index 0c574e5d..593f1458 100644 --- a/technical-fundamentals/coding/problems/__tests__/lists/11_removeDups.test.ts +++ b/technical-fundamentals/coding/problems/__tests__/lists/11_removeDups.test.ts @@ -54,4 +54,31 @@ describe("11 - removeDups", () => { const result = removeDups(node1); expect(result).toEqual(node1); }); + + test("remove duplicates with heavy interleaving", () => { + const n1 = { value: "a" } as Node; + const n2 = { value: "b" } as Node; + const n3 = { value: "a" } as Node; + const n4 = { value: "c" } as Node; + const n5 = { value: "b" } as Node; + const n6 = { value: "d" } as Node; + const n7 = { value: "c" } as Node; + const n8 = { value: "a" } as Node; + + n1.next = n2; + n2.next = n3; + n3.next = n4; + n4.next = n5; + n5.next = n6; + n6.next = n7; + n7.next = n8; + + const expected = { value: "a" } as Node; + expected.next = { value: "b" } as Node; + expected.next.next = { value: "c" } as Node; + expected.next.next.next = { value: "d" } as Node; + + const result = removeDups(n1); + expect(result).toEqual(expected); + }); }); From 0d4f0a031aed56d202eac093e2be6ab376b01c4e Mon Sep 17 00:00:00 2001 From: Marcos Tonina Date: Sat, 7 Feb 2026 20:31:46 -0300 Subject: [PATCH 11/20] Fixing scenario 12 with two approaches --- .../coding/problems/10_LinkedList.ts | 18 +++++++++-- .../coding/problems/12_kthToLast.ts | 31 +++++++++++++++++-- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/technical-fundamentals/coding/problems/10_LinkedList.ts b/technical-fundamentals/coding/problems/10_LinkedList.ts index 3e39f282..187a06dd 100644 --- a/technical-fundamentals/coding/problems/10_LinkedList.ts +++ b/technical-fundamentals/coding/problems/10_LinkedList.ts @@ -41,7 +41,14 @@ export class LinkedList { return result; } - visit() { + visit(fn: (node: Node, index: number) => void) { + let index = 0; + let p = this.head; + while(p){ + fn(p, index); + index++; + p = p.next; + } } remove() { @@ -58,7 +65,14 @@ export class LinkedList { //find(): Node {} //get(index: number): Node {} //iterator(): LinkedListIterator {} - length: number; + + length(): number { + let length = 0; + this.visit(() => { + length++; + }); + return length; + } } const list = new LinkedList(); diff --git a/technical-fundamentals/coding/problems/12_kthToLast.ts b/technical-fundamentals/coding/problems/12_kthToLast.ts index 460e6528..de42fc61 100644 --- a/technical-fundamentals/coding/problems/12_kthToLast.ts +++ b/technical-fundamentals/coding/problems/12_kthToLast.ts @@ -8,8 +8,33 @@ export type Node = { value: T; next?: Node; }; - export default function kthToLast( - head: Node, + head: Node | undefined, + k: number, +): Node | undefined { + let lList: LinkedList = new LinkedList(head); + const length = lList.length(); + let ret; + lList.visit((node, index) => { + if(index === length - k){ + ret = node; + } + }); + return ret; +} + +//this is O(n) but uses an array as helper +export function kthToLast2( + head: Node | undefined, k: number, -): Node | undefined {} +): Node | undefined { + const array = []; + let p = head; + let counter = 0; + while(p){ + array[counter] = p; + counter++; + p = p.next; + } + return array[counter-k]; +} From 47567719aa4c14f15208a223030cfcf5cc8c379f Mon Sep 17 00:00:00 2001 From: Marcos Tonina Date: Sun, 8 Feb 2026 14:18:01 -0300 Subject: [PATCH 12/20] Fixing scenario 13 with two approaches --- .../coding/problems/13_deleteMiddleNode.ts | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/technical-fundamentals/coding/problems/13_deleteMiddleNode.ts b/technical-fundamentals/coding/problems/13_deleteMiddleNode.ts index b9bb4464..f7134965 100644 --- a/technical-fundamentals/coding/problems/13_deleteMiddleNode.ts +++ b/technical-fundamentals/coding/problems/13_deleteMiddleNode.ts @@ -20,4 +20,38 @@ export type Node = { export default function deleteMiddleNode( head: Node, position: number, -): Node | undefined {} +): Node | undefined { + + if(position < 0) return head; + + const lList = new LinkedList(head); + lList.visit((node, index) => { + if(index === position - 1 && node.next && node.next.next){ + node.next = node.next.next; + return lList.head; + } + }); + return head; +} + +export function deleteMiddleNode2( + head: Node, + position: number, +): Node | undefined { + + let p: Node | undefined = head; + let index = 0; + if(position < 0) return head; + + while(p){ + if(index === position-1 && p.next && p.next.next) { + p.next = p.next.next; + return head; + } + index++; + p = p.next; + } + + return head; + +} From 47303b2f5a53584674a1739659508deb89ac6ed6 Mon Sep 17 00:00:00 2001 From: Marcos Tonina Date: Mon, 16 Feb 2026 18:29:08 -0300 Subject: [PATCH 13/20] Fixing scenario 14 --- .../coding/problems/14_partition.ts | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/technical-fundamentals/coding/problems/14_partition.ts b/technical-fundamentals/coding/problems/14_partition.ts index f680ab7e..53bd602d 100644 --- a/technical-fundamentals/coding/problems/14_partition.ts +++ b/technical-fundamentals/coding/problems/14_partition.ts @@ -18,8 +18,41 @@ export type Node = { value: T; next?: Node; }; - export default function partition( head: Node | undefined, x: T, -): Node | undefined {} +): Node | undefined { + + if(!head) return head; + + let p = head; + let auxList: Node = {value: {} as T}; + const auxHead = auxList; + let firstHead: Node | undefined = head; + + while(firstHead && firstHead.value < x){ + auxList.next = firstHead; + auxList = auxList.next; + firstHead = firstHead.next; + } + + const lList = new LinkedList(firstHead); + + lList.visit((n) => { + if(n.next && n.next.value < x) { + auxList.next = n.next; + n.next = n.next.next; + auxList = auxList.next; + if(n.next && !n.next.next && n.next.value < x){ + auxList.next = n.next; + auxList = auxList.next; + n.next = undefined; + } + } + }); + + auxList.next = firstHead; + return auxHead.next; + +} + From 46144db606a9fe073c9569362c48baa2dfa0a00b Mon Sep 17 00:00:00 2001 From: Marcos Tonina Date: Mon, 16 Feb 2026 20:03:03 -0300 Subject: [PATCH 14/20] Fixing scenario 15 --- .../coding/problems/15_sumLists.ts | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/technical-fundamentals/coding/problems/15_sumLists.ts b/technical-fundamentals/coding/problems/15_sumLists.ts index fce352a1..cf69d06e 100644 --- a/technical-fundamentals/coding/problems/15_sumLists.ts +++ b/technical-fundamentals/coding/problems/15_sumLists.ts @@ -19,4 +19,40 @@ export type Node = { export default function sumLists( list1: Node | undefined, list2: Node | undefined, -): Node | undefined {} +): Node | undefined { + + let multiplier = 1; + let result = 0; + while(list1 || list2){ + let val1; + let val2; + if(!list1) { + val1 = 0; + } else { + val1 = list1.value; + } + if(!list2) { + val2 = 0; + } else { + val2 = list2.value; + } + + result += (val1 + val2) * multiplier; + multiplier *= 10; + + list1 = list1?.next; + list2 = list2?.next; + + } + let resultNode: Node = {value: {} as number}; + const resHead = resultNode; + while(result >= 1){ + const nextD = result % 10; + result = Math.floor(result / 10); + resultNode.next = {value: nextD}; + resultNode = resultNode.next; + } + + return resHead.next; + +} From 09d849be3997cc19fba2635ca371364d203de8c9 Mon Sep 17 00:00:00 2001 From: Marcos Tonina Date: Mon, 16 Feb 2026 20:15:46 -0300 Subject: [PATCH 15/20] Fixing scenario 16 --- .../problems/16_sumListsForwardOrder.ts | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/technical-fundamentals/coding/problems/16_sumListsForwardOrder.ts b/technical-fundamentals/coding/problems/16_sumListsForwardOrder.ts index 2f426d55..9b3974e6 100644 --- a/technical-fundamentals/coding/problems/16_sumListsForwardOrder.ts +++ b/technical-fundamentals/coding/problems/16_sumListsForwardOrder.ts @@ -16,4 +16,25 @@ export type Node = { export default function sumListsForwardOrder( list1: Node | undefined, list2: Node | undefined, -): Node | undefined {} +): Node | undefined { + let result: number = getNumber(list1) + getNumber(list2); + if(result === 0) return undefined; + let resList: Node = {value: {} as number} + const resHead = resList; + const str = String(result); + for(let i = 0; i < str.length; i++){ + resList.next = {value: Number(str[i])} + resList = resList.next; + } + return resHead.next; +} + +function getNumber(list : Node): number{ + if(!list) return 0; + const lList = new LinkedList(list); + let str = ""; + lList.visit((n: Node) => { + str += n.value; + }); + return Number(str); +} From 1726c575c98c9006e1b4ef1700dbff00afa3190f Mon Sep 17 00:00:00 2001 From: Marcos Tonina Date: Mon, 16 Feb 2026 20:20:36 -0300 Subject: [PATCH 16/20] Fixing scenario 17 --- .../coding/problems/17_palindrome.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/technical-fundamentals/coding/problems/17_palindrome.ts b/technical-fundamentals/coding/problems/17_palindrome.ts index 863c2ff2..7f9d3a47 100644 --- a/technical-fundamentals/coding/problems/17_palindrome.ts +++ b/technical-fundamentals/coding/problems/17_palindrome.ts @@ -9,4 +9,14 @@ export type Node = { next?: Node; }; -export default function isPalindrome(head: Node | undefined): boolean {} +export default function isPalindrome(head: Node | undefined): boolean { + let str1 = ""; + let str2 = ""; + if(!head) return false; + const lList = new LinkedList(head); + lList.visit((n) => { + str1 += n.value; + str2 = n.value + str2; + }); + return str1 === str2; +} From 3c9e0f5766cf080139eb312cd3ddbea47aa48ddd Mon Sep 17 00:00:00 2001 From: Marcos Tonina Date: Mon, 16 Feb 2026 20:30:44 -0300 Subject: [PATCH 17/20] Fixing scenario 18 --- .../coding/problems/18_intersection.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/technical-fundamentals/coding/problems/18_intersection.ts b/technical-fundamentals/coding/problems/18_intersection.ts index e9f50487..b4b9b1ca 100644 --- a/technical-fundamentals/coding/problems/18_intersection.ts +++ b/technical-fundamentals/coding/problems/18_intersection.ts @@ -14,4 +14,16 @@ export type Node = { export default function intersection( list1: Node | undefined, list2: Node | undefined, -): Node | undefined {} +): Node | undefined { + const map: Map, boolean> = new Map, boolean>(); + const lList1 = new LinkedList(list1); + lList1.visit((n) => { + map.set(n, true); + }); + let p = list2; + while(p){ + if(map.has(p)) return p; + p = p.next; + } + +} From 8209f94769b6990b34ed71bbeb04bce5c872c7d6 Mon Sep 17 00:00:00 2001 From: Marcos Tonina Date: Mon, 16 Feb 2026 20:36:56 -0300 Subject: [PATCH 18/20] Fixing scenario 19 --- .../coding/problems/19_loopDetection.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/technical-fundamentals/coding/problems/19_loopDetection.ts b/technical-fundamentals/coding/problems/19_loopDetection.ts index d91c0b21..87826ef8 100644 --- a/technical-fundamentals/coding/problems/19_loopDetection.ts +++ b/technical-fundamentals/coding/problems/19_loopDetection.ts @@ -24,4 +24,16 @@ export type Node = { export default function detectLoop( head: Node | undefined, -): Node | null {} +): Node | null { + const map: Map, boolean> = new Map, boolean>(); + let p = head; + while(p){ + if(map.has(p)){ + return p; + } else { + map.set(p, true); + } + p = p.next; + } + return null; +} From 979aa632b149fc6c9219e27f224925ba79dc47e3 Mon Sep 17 00:00:00 2001 From: Marcos Tonina Date: Tue, 17 Feb 2026 11:50:10 -0300 Subject: [PATCH 19/20] Fixing scenario 14 with correct approach --- .../coding/problems/10_LinkedList.ts | 6 +++++- .../coding/problems/14_partition.ts | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/technical-fundamentals/coding/problems/10_LinkedList.ts b/technical-fundamentals/coding/problems/10_LinkedList.ts index 187a06dd..cd8dec69 100644 --- a/technical-fundamentals/coding/problems/10_LinkedList.ts +++ b/technical-fundamentals/coding/problems/10_LinkedList.ts @@ -54,7 +54,11 @@ export class LinkedList { remove() { } - merge() { + merge(list: LinkedList): LinkedList { + if(!this.tail) return list; + this.tail.next = list.head; + this.tail = list.tail; + return this; } print() { diff --git a/technical-fundamentals/coding/problems/14_partition.ts b/technical-fundamentals/coding/problems/14_partition.ts index 53bd602d..ec9dc0ad 100644 --- a/technical-fundamentals/coding/problems/14_partition.ts +++ b/technical-fundamentals/coding/problems/14_partition.ts @@ -23,6 +23,23 @@ export default function partition( x: T, ): Node | undefined { + const lList = new LinkedList(head); + const front = lList.filter((n) => { + return n.value < x; + }); + const back = lList.filter((n) => { + return n.value >= x; + }); + + return front.merge(back).head; +} + +//I made this without filter() and merge() +export function partition2( + head: Node | undefined, + x: T, +): Node | undefined { + if(!head) return head; let p = head; From 9d0bead74109a7c34f441e6c0c92c63397622c31 Mon Sep 17 00:00:00 2001 From: Marcos Tonina Date: Tue, 17 Feb 2026 12:09:28 -0300 Subject: [PATCH 20/20] Fixing scenarios with video solutions --- .../coding/problems/13_deleteMiddleNode.ts | 1 + .../coding/problems/16_sumListsForwardOrder.ts | 2 +- technical-fundamentals/coding/problems/18_intersection.ts | 8 ++++---- .../coding/problems/19_loopDetection.ts | 6 +++--- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/technical-fundamentals/coding/problems/13_deleteMiddleNode.ts b/technical-fundamentals/coding/problems/13_deleteMiddleNode.ts index f7134965..d1d4e7c5 100644 --- a/technical-fundamentals/coding/problems/13_deleteMiddleNode.ts +++ b/technical-fundamentals/coding/problems/13_deleteMiddleNode.ts @@ -30,6 +30,7 @@ export default function deleteMiddleNode( node.next = node.next.next; return lList.head; } + return null; }); return head; } diff --git a/technical-fundamentals/coding/problems/16_sumListsForwardOrder.ts b/technical-fundamentals/coding/problems/16_sumListsForwardOrder.ts index 9b3974e6..37431355 100644 --- a/technical-fundamentals/coding/problems/16_sumListsForwardOrder.ts +++ b/technical-fundamentals/coding/problems/16_sumListsForwardOrder.ts @@ -29,7 +29,7 @@ export default function sumListsForwardOrder( return resHead.next; } -function getNumber(list : Node): number{ +function getNumber(list : Node | undefined): number{ if(!list) return 0; const lList = new LinkedList(list); let str = ""; diff --git a/technical-fundamentals/coding/problems/18_intersection.ts b/technical-fundamentals/coding/problems/18_intersection.ts index b4b9b1ca..f674cd19 100644 --- a/technical-fundamentals/coding/problems/18_intersection.ts +++ b/technical-fundamentals/coding/problems/18_intersection.ts @@ -15,15 +15,15 @@ export default function intersection( list1: Node | undefined, list2: Node | undefined, ): Node | undefined { - const map: Map, boolean> = new Map, boolean>(); + const set: Set> = new Set>(); const lList1 = new LinkedList(list1); lList1.visit((n) => { - map.set(n, true); + set.add(n); }); let p = list2; while(p){ - if(map.has(p)) return p; + if(set.has(p)) return p; p = p.next; } - + return undefined; } diff --git a/technical-fundamentals/coding/problems/19_loopDetection.ts b/technical-fundamentals/coding/problems/19_loopDetection.ts index 87826ef8..748bdc24 100644 --- a/technical-fundamentals/coding/problems/19_loopDetection.ts +++ b/technical-fundamentals/coding/problems/19_loopDetection.ts @@ -25,13 +25,13 @@ export type Node = { export default function detectLoop( head: Node | undefined, ): Node | null { - const map: Map, boolean> = new Map, boolean>(); + const set: Set> = new Set>(); let p = head; while(p){ - if(map.has(p)){ + if(set.has(p)){ return p; } else { - map.set(p, true); + set.add(p); } p = p.next; }