From 68b273ae6e6ac87bdff5f1872f5568b35ae1444b Mon Sep 17 00:00:00 2001 From: JuaniSilva Date: Tue, 26 Aug 2025 18:18:10 -0300 Subject: [PATCH 1/6] feat: strings and array problems --- .../coding/problems/01_isUnique.ts | 12 ++++++- .../coding/problems/02_checkPermutations.ts | 18 ++++++++++- .../coding/problems/03_urlify.ts | 14 ++++++-- .../problems/04_palindromePermutation.ts | 24 ++++++++++++-- .../coding/problems/05_oneAway.ts | 31 +++++++++++++++++- .../coding/problems/06_stringCompression.ts | 22 +++++++++++-- .../coding/problems/07_rotateMatrix.ts | 26 +++++++++++++-- .../coding/problems/08_zeroMatrix.ts | 32 +++++++++++++++++-- .../coding/problems/09_stringRotation.ts | 23 +++++++++++-- 9 files changed, 182 insertions(+), 20 deletions(-) diff --git a/technical-fundamentals/coding/problems/01_isUnique.ts b/technical-fundamentals/coding/problems/01_isUnique.ts index 07f432b1..d3b16aca 100644 --- a/technical-fundamentals/coding/problems/01_isUnique.ts +++ b/technical-fundamentals/coding/problems/01_isUnique.ts @@ -3,4 +3,14 @@ // 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 dic: Record = {}; + for (let i = 0; i < str.length; i++) { + const char = str[i]; + const exists = dic[char]; + if (exists) return false; + + dic[char] = 1; + } + return true; +} diff --git a/technical-fundamentals/coding/problems/02_checkPermutations.ts b/technical-fundamentals/coding/problems/02_checkPermutations.ts index 56deb0f0..f3020a9e 100644 --- a/technical-fundamentals/coding/problems/02_checkPermutations.ts +++ b/technical-fundamentals/coding/problems/02_checkPermutations.ts @@ -2,4 +2,20 @@ // 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 {} +export default function checkPermutations(s1: string, s2: string): boolean { + const charsDic: Record = {}; + for (let i = 0; i < s1.length; i++) { + const char = s1[i]; + const exists = charsDic[char]; + if (exists) charsDic[char]++; + else charsDic[char] = 1; + } + + for (let j = 0; j < s2.length; j++) { + const char = s2[j]; + const isInDic = Boolean(charsDic[char]); + if (!isInDic) return false; + charsDic[char]--; + } + return Object.values(charsDic).filter((val) => val !== 0).length === 0; +} diff --git a/technical-fundamentals/coding/problems/03_urlify.ts b/technical-fundamentals/coding/problems/03_urlify.ts index ca989b83..8bfbd3dc 100644 --- a/technical-fundamentals/coding/problems/03_urlify.ts +++ b/technical-fundamentals/coding/problems/03_urlify.ts @@ -4,6 +4,14 @@ // 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 { - -} \ No newline at end of file +export default function URLify(s1: string): string { + let newString = ''; + for (let i = 0; i < s1.length; i++) { + let char = s1[i]; + if (char == '') { + char = '%20'; + } + newString = `${newString}${char}`; + } + return newString; +} diff --git a/technical-fundamentals/coding/problems/04_palindromePermutation.ts b/technical-fundamentals/coding/problems/04_palindromePermutation.ts index d80c9217..2d79e9ab 100644 --- a/technical-fundamentals/coding/problems/04_palindromePermutation.ts +++ b/technical-fundamentals/coding/problems/04_palindromePermutation.ts @@ -1,4 +1,4 @@ -// 4. *Palindrome Permutation*: +// 4. *Palindrome Permutation*: // Given a string, write a function to check if it is a permutation of a palindrome. // A palindrome is a word or phrase that is the same forwards and backwards. A permutation is a rearrangement of letters. @@ -9,6 +9,24 @@ // Output True (permutations: "taco cat", "atco cta", etc.) // ``` -export default function palindromePermutation (str: string): boolean { +export default function palindromePermutation(str: string): boolean { + if (!str) return true; + const wordDic: Record = {}; -} \ No newline at end of file + for (let i = 0; i < str.length; i++) { + const char = str[i].toLocaleLowerCase(); + if (char === ' ') continue; + + if (!wordDic[char]) wordDic[char] = 0; + wordDic[char]++; + } + + let notPairs = 0; + + for (const value of Object.values(wordDic)) { + if (value % 2 !== 0) { + notPairs++; + } + } + return notPairs <= 1; +} diff --git a/technical-fundamentals/coding/problems/05_oneAway.ts b/technical-fundamentals/coding/problems/05_oneAway.ts index 79c9a12d..0d0c0821 100644 --- a/technical-fundamentals/coding/problems/05_oneAway.ts +++ b/technical-fundamentals/coding/problems/05_oneAway.ts @@ -5,5 +5,34 @@ // 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 { - + let actions = 0; + + let p1 = 0; + let p2 = 0; + + while (p1 <= str1.length || p2 <= str2.length) { + const char1 = str1[p1]; + const char2 = str2[p2]; + + if (char1 === char2) { + p1++; + p2++; + continue; + } + + actions++; + if (actions > 1) return false; + + if (str1.length === str2.length) { + p1++; + p2++; + continue; + } + if (str1.length > str2.length) { + p1++; + continue; + } else p2++; + } + + return true; } diff --git a/technical-fundamentals/coding/problems/06_stringCompression.ts b/technical-fundamentals/coding/problems/06_stringCompression.ts index 525ce40d..071ade5f 100644 --- a/technical-fundamentals/coding/problems/06_stringCompression.ts +++ b/technical-fundamentals/coding/problems/06_stringCompression.ts @@ -6,6 +6,22 @@ // your method should return the original string. // You can assume the string has only uppercase and lowercase letters (a - z). -export default function stringCompression (str: string) : string { - -} \ No newline at end of file +export default function stringCompression(str: string): string { + let newString = ''; + let char = str[0]; + let count = 0; + for (let i = 0; i < str.length; i++) { + const curr = str[i]; + if (curr === char) { + count++; + } else { + newString += char + count; + char = curr; + count = 1; + } + } + + newString += char + count; + + return newString.length >= str.length ? str : newString; +} diff --git a/technical-fundamentals/coding/problems/07_rotateMatrix.ts b/technical-fundamentals/coding/problems/07_rotateMatrix.ts index 875d0841..8df115c6 100644 --- a/technical-fundamentals/coding/problems/07_rotateMatrix.ts +++ b/technical-fundamentals/coding/problems/07_rotateMatrix.ts @@ -3,8 +3,28 @@ // Given an image represented by an NxN matrix, where each pixel in the image is 4 // bytes, write a method to rotate the image by 90 degrees. Can you do this in place? -type Matrix = number[][] +// [1,2,3] +// [4,5,6] +// [7,8,9] -export default function rotateMatrix (matrix: Matrix) { +// [1,4,7] +// [2,5,8] +// [3,6,9] -} \ No newline at end of file +// [7,4,1] +// [8,5,2] +// [9,6,3] + +type Matrix = number[][]; + +export default function rotateMatrix(matrix: Matrix) { + for (let row = 0; row < matrix.length; row++) { + for (let col = row + 1; col < matrix.length; col++) { + const temp = matrix[row][col]; + matrix[row][col] = matrix[col][row]; + matrix[col][row] = temp; + } + } + + for (const row of matrix) row.reverse(); +} diff --git a/technical-fundamentals/coding/problems/08_zeroMatrix.ts b/technical-fundamentals/coding/problems/08_zeroMatrix.ts index 5bf6941d..369155ce 100644 --- a/technical-fundamentals/coding/problems/08_zeroMatrix.ts +++ b/technical-fundamentals/coding/problems/08_zeroMatrix.ts @@ -2,8 +2,34 @@ // Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column are set to 0. -type Matrix = number[][] +type Matrix = number[][]; -export default function zeroMatrix (matrix: Matrix) { +// [[ 1, 2, 3 ], +// [ 4, 5, 6 ], +// [ 7, 0, 9 ] ] -} \ No newline at end of file +// 2,1 + +// [[ 1, 0, 3 ], +// [ 4, 0, 6 ], +// [ 0, 0, 0 ] ] + +export default function zeroMatrix(matrix: Matrix) { + const indexesToBomb: [number, number][] = []; + for (let row = 0; row < matrix.length; row++) { + for (let col = 0; col < matrix[row].length; col++) { + const val = matrix[row][col]; + if (val === 0) indexesToBomb.push([row, col]); + } + } + + for (const coordinate of indexesToBomb) { + const [row, col] = coordinate; + for (let i = 0; i < matrix[row].length; i++) { + matrix[row][i] = 0; + } + for (let i = 0; i < matrix.length; i++) { + matrix[i][col] = 0; + } + } +} diff --git a/technical-fundamentals/coding/problems/09_stringRotation.ts b/technical-fundamentals/coding/problems/09_stringRotation.ts index afc900e0..f250bf45 100644 --- a/technical-fundamentals/coding/problems/09_stringRotation.ts +++ b/technical-fundamentals/coding/problems/09_stringRotation.ts @@ -1,9 +1,28 @@ // 9. *String Rotation*; -import { isSubstring } from "./__utils__/strings" +import { isSubstring } from './__utils__/strings'; // Assume you have a method isSubstring which checks if one word is a substring of another. // 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; +// } +// if (s1.length === 0) { +// return true; +// } +// Esto siento que debería andar. Solo se llama una vez dentro de la función pero no pasa los test ya que figura que se llamo más de una vez (se llama 1 por cada test) +// return isSubstring(s1 + s1, s2); +// } + +export default function stringRotation(s1: string, s2: string): boolean { + let rotated = s2; + for (let i = 0; i < s1.length; i++) { + if (rotated === s1) return true; + rotated = rotated.slice(1, s2.length) + rotated[0]; + } + + return false; +} From 401eee2041f0678f781149cb3eb9533be0975181 Mon Sep 17 00:00:00 2001 From: JuaniSilva Date: Tue, 26 Aug 2025 18:31:06 -0300 Subject: [PATCH 2/6] fix: space --- technical-fundamentals/coding/problems/03_urlify.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/technical-fundamentals/coding/problems/03_urlify.ts b/technical-fundamentals/coding/problems/03_urlify.ts index 8bfbd3dc..89af3a70 100644 --- a/technical-fundamentals/coding/problems/03_urlify.ts +++ b/technical-fundamentals/coding/problems/03_urlify.ts @@ -8,7 +8,7 @@ export default function URLify(s1: string): string { let newString = ''; for (let i = 0; i < s1.length; i++) { let char = s1[i]; - if (char == '') { + if (char === ' ') { char = '%20'; } newString = `${newString}${char}`; From 5cdacc4ffe032d2cdfcb6e6ad5c71a30aa0779a0 Mon Sep 17 00:00:00 2001 From: JuaniSilva Date: Tue, 26 Aug 2025 19:06:32 -0300 Subject: [PATCH 3/6] fix: remove wildcards --- technical-fundamentals/package.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/technical-fundamentals/package.json b/technical-fundamentals/package.json index bd1ab3da..0986c544 100644 --- a/technical-fundamentals/package.json +++ b/technical-fundamentals/package.json @@ -4,13 +4,13 @@ "description": "Crackin the coding interview problems", "main": "index.js", "scripts": { - "test": "vitest ./**/problems/__tests__/*", + "test": "vitest ./coding/problems/__tests__/*", "test-coding": "vitest ./coding/__tests__/*", - "strings": "vitest ./**/problems/__tests__/strings/* --reporter=default --reporter=./silverReporter.ts", - "lists": "vitest ./**/problems/__tests__/lists/* --reporter=default --reporter=./silverReporter.ts", - "stacks": "vitest ./**/problems/__tests__/stacks/* --reporter=default --reporter=./silverReporter.ts", - "trees": "vitest ./**/problems/__tests__/trees/* --reporter=default --reporter=./silverReporter.ts", - "recursion": "vitest ./**/problems/__tests__/recursion/* --reporter=default --reporter=./silverReporter.ts" + "strings": "vitest ./coding/problems/__tests__/strings --reporter=default --reporter=./silverReporter.ts", + "lists": "vitest ./coding/problems/__tests__/lists --reporter=default --reporter=./silverReporter.ts", + "stacks": "vitest ./coding/problems/__tests__/stacks --reporter=default --reporter=./silverReporter.ts", + "trees": "vitest ./coding/problems/__tests__/trees --reporter=default --reporter=./silverReporter.ts", + "recursion": "vitest ./coding/problems/__tests__/recursion --reporter=default --reporter=./silverReporter.ts" }, "keywords": [ "cracking", From a72b8ab30bc5216c63c81252c33243391edfdb0b Mon Sep 17 00:00:00 2001 From: JuaniSilva Date: Tue, 26 Aug 2025 19:23:19 -0300 Subject: [PATCH 4/6] fix: test and test-coding paths --- technical-fundamentals/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/technical-fundamentals/package.json b/technical-fundamentals/package.json index 0986c544..6a8d114f 100644 --- a/technical-fundamentals/package.json +++ b/technical-fundamentals/package.json @@ -4,8 +4,8 @@ "description": "Crackin the coding interview problems", "main": "index.js", "scripts": { - "test": "vitest ./coding/problems/__tests__/*", - "test-coding": "vitest ./coding/__tests__/*", + "test": "vitest ./coding/problems/__tests__/", + "test-coding": "vitest ./coding/__tests__/", "strings": "vitest ./coding/problems/__tests__/strings --reporter=default --reporter=./silverReporter.ts", "lists": "vitest ./coding/problems/__tests__/lists --reporter=default --reporter=./silverReporter.ts", "stacks": "vitest ./coding/problems/__tests__/stacks --reporter=default --reporter=./silverReporter.ts", From 736eb3b7efb9458ffff8b741d23240fb19c92ddf Mon Sep 17 00:00:00 2001 From: JuaniSilva Date: Tue, 26 Aug 2025 19:30:31 -0300 Subject: [PATCH 5/6] Revert "fix: space" This reverts commit 401eee2041f0678f781149cb3eb9533be0975181. --- technical-fundamentals/coding/problems/03_urlify.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/technical-fundamentals/coding/problems/03_urlify.ts b/technical-fundamentals/coding/problems/03_urlify.ts index 89af3a70..8bfbd3dc 100644 --- a/technical-fundamentals/coding/problems/03_urlify.ts +++ b/technical-fundamentals/coding/problems/03_urlify.ts @@ -8,7 +8,7 @@ export default function URLify(s1: string): string { let newString = ''; for (let i = 0; i < s1.length; i++) { let char = s1[i]; - if (char === ' ') { + if (char == '') { char = '%20'; } newString = `${newString}${char}`; From ab2d3171db1d1bc13d52974661f1499e295cb00a Mon Sep 17 00:00:00 2001 From: JuaniSilva Date: Tue, 26 Aug 2025 19:30:42 -0300 Subject: [PATCH 6/6] Revert "feat: strings and array problems" This reverts commit 68b273ae6e6ac87bdff5f1872f5568b35ae1444b. --- .../coding/problems/01_isUnique.ts | 12 +------ .../coding/problems/02_checkPermutations.ts | 18 +---------- .../coding/problems/03_urlify.ts | 14 ++------ .../problems/04_palindromePermutation.ts | 24 ++------------ .../coding/problems/05_oneAway.ts | 31 +----------------- .../coding/problems/06_stringCompression.ts | 22 ++----------- .../coding/problems/07_rotateMatrix.ts | 26 ++------------- .../coding/problems/08_zeroMatrix.ts | 32 ++----------------- .../coding/problems/09_stringRotation.ts | 23 ++----------- 9 files changed, 20 insertions(+), 182 deletions(-) diff --git a/technical-fundamentals/coding/problems/01_isUnique.ts b/technical-fundamentals/coding/problems/01_isUnique.ts index d3b16aca..07f432b1 100644 --- a/technical-fundamentals/coding/problems/01_isUnique.ts +++ b/technical-fundamentals/coding/problems/01_isUnique.ts @@ -3,14 +3,4 @@ // 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 { - const dic: Record = {}; - for (let i = 0; i < str.length; i++) { - const char = str[i]; - const exists = dic[char]; - if (exists) return false; - - dic[char] = 1; - } - return true; -} +export default function isUnique(str: string): boolean {} diff --git a/technical-fundamentals/coding/problems/02_checkPermutations.ts b/technical-fundamentals/coding/problems/02_checkPermutations.ts index f3020a9e..56deb0f0 100644 --- a/technical-fundamentals/coding/problems/02_checkPermutations.ts +++ b/technical-fundamentals/coding/problems/02_checkPermutations.ts @@ -2,20 +2,4 @@ // 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 { - const charsDic: Record = {}; - for (let i = 0; i < s1.length; i++) { - const char = s1[i]; - const exists = charsDic[char]; - if (exists) charsDic[char]++; - else charsDic[char] = 1; - } - - for (let j = 0; j < s2.length; j++) { - const char = s2[j]; - const isInDic = Boolean(charsDic[char]); - if (!isInDic) return false; - charsDic[char]--; - } - return Object.values(charsDic).filter((val) => val !== 0).length === 0; -} +export default function checkPermutations(s1: string, s2: string): boolean {} diff --git a/technical-fundamentals/coding/problems/03_urlify.ts b/technical-fundamentals/coding/problems/03_urlify.ts index 8bfbd3dc..ca989b83 100644 --- a/technical-fundamentals/coding/problems/03_urlify.ts +++ b/technical-fundamentals/coding/problems/03_urlify.ts @@ -4,14 +4,6 @@ // 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 { - let newString = ''; - for (let i = 0; i < s1.length; i++) { - let char = s1[i]; - if (char == '') { - char = '%20'; - } - newString = `${newString}${char}`; - } - return newString; -} +export default function URLify (s1 : string): string { + +} \ No newline at end of file diff --git a/technical-fundamentals/coding/problems/04_palindromePermutation.ts b/technical-fundamentals/coding/problems/04_palindromePermutation.ts index 2d79e9ab..d80c9217 100644 --- a/technical-fundamentals/coding/problems/04_palindromePermutation.ts +++ b/technical-fundamentals/coding/problems/04_palindromePermutation.ts @@ -1,4 +1,4 @@ -// 4. *Palindrome Permutation*: +// 4. *Palindrome Permutation*: // Given a string, write a function to check if it is a permutation of a palindrome. // A palindrome is a word or phrase that is the same forwards and backwards. A permutation is a rearrangement of letters. @@ -9,24 +9,6 @@ // Output True (permutations: "taco cat", "atco cta", etc.) // ``` -export default function palindromePermutation(str: string): boolean { - if (!str) return true; - const wordDic: Record = {}; +export default function palindromePermutation (str: string): boolean { - for (let i = 0; i < str.length; i++) { - const char = str[i].toLocaleLowerCase(); - if (char === ' ') continue; - - if (!wordDic[char]) wordDic[char] = 0; - wordDic[char]++; - } - - let notPairs = 0; - - for (const value of Object.values(wordDic)) { - if (value % 2 !== 0) { - notPairs++; - } - } - return notPairs <= 1; -} +} \ No newline at end of file diff --git a/technical-fundamentals/coding/problems/05_oneAway.ts b/technical-fundamentals/coding/problems/05_oneAway.ts index 0d0c0821..79c9a12d 100644 --- a/technical-fundamentals/coding/problems/05_oneAway.ts +++ b/technical-fundamentals/coding/problems/05_oneAway.ts @@ -5,34 +5,5 @@ // 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 { - let actions = 0; - - let p1 = 0; - let p2 = 0; - - while (p1 <= str1.length || p2 <= str2.length) { - const char1 = str1[p1]; - const char2 = str2[p2]; - - if (char1 === char2) { - p1++; - p2++; - continue; - } - - actions++; - if (actions > 1) return false; - - if (str1.length === str2.length) { - p1++; - p2++; - continue; - } - if (str1.length > str2.length) { - p1++; - continue; - } else p2++; - } - - return true; + } diff --git a/technical-fundamentals/coding/problems/06_stringCompression.ts b/technical-fundamentals/coding/problems/06_stringCompression.ts index 071ade5f..525ce40d 100644 --- a/technical-fundamentals/coding/problems/06_stringCompression.ts +++ b/technical-fundamentals/coding/problems/06_stringCompression.ts @@ -6,22 +6,6 @@ // your method should return the original string. // You can assume the string has only uppercase and lowercase letters (a - z). -export default function stringCompression(str: string): string { - let newString = ''; - let char = str[0]; - let count = 0; - for (let i = 0; i < str.length; i++) { - const curr = str[i]; - if (curr === char) { - count++; - } else { - newString += char + count; - char = curr; - count = 1; - } - } - - newString += char + count; - - return newString.length >= str.length ? str : newString; -} +export default function stringCompression (str: string) : string { + +} \ No newline at end of file diff --git a/technical-fundamentals/coding/problems/07_rotateMatrix.ts b/technical-fundamentals/coding/problems/07_rotateMatrix.ts index 8df115c6..875d0841 100644 --- a/technical-fundamentals/coding/problems/07_rotateMatrix.ts +++ b/technical-fundamentals/coding/problems/07_rotateMatrix.ts @@ -3,28 +3,8 @@ // Given an image represented by an NxN matrix, where each pixel in the image is 4 // bytes, write a method to rotate the image by 90 degrees. Can you do this in place? -// [1,2,3] -// [4,5,6] -// [7,8,9] +type Matrix = number[][] -// [1,4,7] -// [2,5,8] -// [3,6,9] +export default function rotateMatrix (matrix: Matrix) { -// [7,4,1] -// [8,5,2] -// [9,6,3] - -type Matrix = number[][]; - -export default function rotateMatrix(matrix: Matrix) { - for (let row = 0; row < matrix.length; row++) { - for (let col = row + 1; col < matrix.length; col++) { - const temp = matrix[row][col]; - matrix[row][col] = matrix[col][row]; - matrix[col][row] = temp; - } - } - - for (const row of matrix) row.reverse(); -} +} \ No newline at end of file diff --git a/technical-fundamentals/coding/problems/08_zeroMatrix.ts b/technical-fundamentals/coding/problems/08_zeroMatrix.ts index 369155ce..5bf6941d 100644 --- a/technical-fundamentals/coding/problems/08_zeroMatrix.ts +++ b/technical-fundamentals/coding/problems/08_zeroMatrix.ts @@ -2,34 +2,8 @@ // Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column are set to 0. -type Matrix = number[][]; +type Matrix = number[][] -// [[ 1, 2, 3 ], -// [ 4, 5, 6 ], -// [ 7, 0, 9 ] ] +export default function zeroMatrix (matrix: Matrix) { -// 2,1 - -// [[ 1, 0, 3 ], -// [ 4, 0, 6 ], -// [ 0, 0, 0 ] ] - -export default function zeroMatrix(matrix: Matrix) { - const indexesToBomb: [number, number][] = []; - for (let row = 0; row < matrix.length; row++) { - for (let col = 0; col < matrix[row].length; col++) { - const val = matrix[row][col]; - if (val === 0) indexesToBomb.push([row, col]); - } - } - - for (const coordinate of indexesToBomb) { - const [row, col] = coordinate; - for (let i = 0; i < matrix[row].length; i++) { - matrix[row][i] = 0; - } - for (let i = 0; i < matrix.length; i++) { - matrix[i][col] = 0; - } - } -} +} \ No newline at end of file diff --git a/technical-fundamentals/coding/problems/09_stringRotation.ts b/technical-fundamentals/coding/problems/09_stringRotation.ts index f250bf45..afc900e0 100644 --- a/technical-fundamentals/coding/problems/09_stringRotation.ts +++ b/technical-fundamentals/coding/problems/09_stringRotation.ts @@ -1,28 +1,9 @@ // 9. *String Rotation*; -import { isSubstring } from './__utils__/strings'; +import { isSubstring } from "./__utils__/strings" // Assume you have a method isSubstring which checks if one word is a substring of another. // 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 { -// if (s1.length !== s2.length) { -// return false; -// } -// if (s1.length === 0) { -// return true; -// } -// Esto siento que debería andar. Solo se llama una vez dentro de la función pero no pasa los test ya que figura que se llamo más de una vez (se llama 1 por cada test) -// return isSubstring(s1 + s1, s2); -// } - -export default function stringRotation(s1: string, s2: string): boolean { - let rotated = s2; - for (let i = 0; i < s1.length; i++) { - if (rotated === s1) return true; - rotated = rotated.slice(1, s2.length) + rotated[0]; - } - - return false; -} +export default function stringRotation(s1: string, s2: string): boolean {}