Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion technical-fundamentals/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
*copy*
*copy*
venv
11 changes: 10 additions & 1 deletion technical-fundamentals/coding/problems/01_isUnique.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,13 @@
// 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 {
let nonRpeatChar = new Set()
for (let i = 0; i < str.length; i++) {
if (nonRpeatChar.has(str[i])){
return false
}
nonRpeatChar.add(str[i])
}
return true
}
17 changes: 16 additions & 1 deletion technical-fundamentals/coding/problems/02_checkPermutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,19 @@

// 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 {
if (s1.length != s2.length) {
return false;
}
const count: Record<string, number> = {};
for (const char of s1) {
count[char] = (count[char] || 0) + 1;
}
for (const char of s2) {
if (!count[char]) {
return false;
}
count[char] --;
}
return true;
}
10 changes: 9 additions & 1 deletion technical-fundamentals/coding/problems/03_urlify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,13 @@
// and that you are given the "true" length of the string.

export default function URLify (s1 : string): string {

let res: string = ""
for (let i = 0; i < s1.length; i++) {
if (s1[i] == " ") {
res += "%20";
} else {
res += s1[i];
}
}
return res
}
28 changes: 28 additions & 0 deletions technical-fundamentals/coding/problems/04_palindromePermutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,33 @@
// ```

export default function palindromePermutation (str: string): boolean {
let normalized: string = "";

for (let i = 0; i < str.length; i++) {
if (/[a-zA-Z0-9]/.test(str[i])) {
normalized += str[i].toLowerCase();
}
}

const charCounts: { [key: string]: number} = {};
for (let i = 0; i < normalized.length; i++) {
const char = normalized[i];
if (charCounts[char]) {
charCounts[char] += 1;
}else {
charCounts[char] = 1;
}
}

let oddCount = 0;
for (const char in charCounts) {
if (charCounts[char] % 2 !== 0) {
oddCount += 1;
if (oddCount > 1) {
return false;
}
}
}

return true
}
35 changes: 34 additions & 1 deletion technical-fundamentals/coding/problems/05_oneAway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,38 @@
// 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 (Math.abs(str1.length - str2.length) > 1) {
return false;
}

const s1 = str1.length < str2.length ? str1 : str2;
const s2 = str1.length < str2.length ? str2 : str1;

let index1 = 0;
let index2 = 0;
let foundDifference = false;

while (index1 < s1.length && index2 < s2.length) {
if (s1[index1] !== s2[index2]) {
if (foundDifference) {
return false;
}
foundDifference = true;

if (s1.length === s2.length) {
// replace: move both pointers
index1 += 1;
index2 += 1;
} else {
// insert/remove: skip char in longer string
index2 += 1;
}
} else {
index1 += 1;
index2 += 1;
}
}

return (s2.length - index2) <= 1;
}

19 changes: 18 additions & 1 deletion technical-fundamentals/coding/problems/06_stringCompression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,22 @@
// You can assume the string has only uppercase and lowercase letters (a - z).

export default function stringCompression (str: string) : string {

if (!str) {
return "";
}

let count = 1;
let res_compress = "";

for (let i = 1; i < str.length ; i++) {
if (str[i] === str[i -1]) {
count ++;
} else {
res_compress += str[i -1] + count.toString();
count = 1;
}
}
res_compress += str[str.length - 1] + count.toString();

return res_compress.length < str.length ? res_compress : str;
}
18 changes: 18 additions & 0 deletions technical-fundamentals/coding/problems/07_rotateMatrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,23 @@
type Matrix = number[][]

export default function rotateMatrix (matrix: Matrix) {
let n = matrix.length
for(let layer = 0; layer < Math.floor(n / 2); layer++) {
const first = layer
const last = n - 1 - first

for(let i = first; i < last; i++) {
const offset = i - first
const top = matrix[first][i]

// left - top
matrix[first][i] = matrix[last - offset][first]
// bottom - left
matrix[last - offset][first] = matrix[last][last - offset]
// right - bottom
matrix[last][last - offset] = matrix[i][last]
// top - right
matrix[i][last] = top
}
}
}
30 changes: 30 additions & 0 deletions technical-fundamentals/coding/problems/08_zeroMatrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,35 @@
type Matrix = number[][]

export default function zeroMatrix (matrix: Matrix) {
if (!matrix || matrix.length === 0 || matrix[0].length === 0) {
return
}
const rows = matrix.length
const columns = matrix[0].length

const zero_rows = new Set<number>()
const zero_columns = new Set<number>()

for (let r = 0; r < rows; r ++) {
for (let c = 0; c < columns; c ++) {
if (matrix[r][c] === 0) {
zero_rows.add(r)
zero_columns.add(c)
}
}
}

// Zero out rows
for (const r of zero_rows) {
for (let c = 0; c < columns; c++) {
matrix[r][c] = 0;
}
}

// Zero out columns
for (const c of zero_columns) {
for (let r = 0; r < rows; r++) {
matrix[r][c] = 0;
}
}
}
8 changes: 7 additions & 1 deletion technical-fundamentals/coding/problems/09_stringRotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ 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
}

return (s1 + s1).includes(s2)
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import unittest
from coding.problems.python_solutions.is_unique import is_unique_chars

class TestIsUnique(unittest.TestCase):

def test_unique_characters(self):
self.assertTrue(is_unique_chars("abc"))
self.assertTrue(is_unique_chars("abcdefg"))
self.assertTrue(is_unique_chars("123456"))
self.assertTrue(is_unique_chars("!@#$%^"))

def test_non_unique_characters(self):
self.assertFalse(is_unique_chars("aab"))
self.assertFalse(is_unique_chars("hello"))
self.assertFalse(is_unique_chars("testing"))
self.assertFalse(is_unique_chars("1234456"))
self.assertFalse(is_unique_chars("abccdef"))

def test_empty_string(self):
self.assertTrue(is_unique_chars(""))

def test_whitespace_handling(self):
self.assertFalse(is_unique_chars("a b c"))
self.assertTrue(is_unique_chars("ab c"))

def test_special_characters(self):
self.assertTrue(is_unique_chars("!@#$%^&*"))
self.assertFalse(is_unique_chars("!@#$%^&*!"))

def test_mixed_case(self):
self.assertTrue(is_unique_chars("aA"))
self.assertTrue(is_unique_chars("Aa"))
self.assertFalse(is_unique_chars("Hello"))

if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import unittest
from coding.problems.python_solutions.check_permutations import check_permutations

class TestCheckPermutations(unittest.TestCase):

def test_permutations_same_length(self):
self.assertTrue(check_permutations("abc", "cba"))

def test_different_lengths(self):
self.assertFalse(check_permutations("abc", "cbad"))

def test_permutations_with_special_characters(self):
self.assertTrue(check_permutations("abc!", "!bac"))

def test_non_permutations_with_special_characters(self):
self.assertFalse(check_permutations("abc!", "!bcd"))

def test_empty_strings(self):
self.assertTrue(check_permutations("", ""))

def test_long_identical_strings(self):
self.assertTrue(check_permutations("a" * 1000, "a" * 1000))

def test_long_different_strings(self):
self.assertFalse(check_permutations("a" * 1000, "b" * 1000))

if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import unittest
from coding.problems.python_solutions.urlify import urlify # Asegúrate de que la función esté definida con este nombre

class TestURLify(unittest.TestCase):

def test_replaces_spaces(self):
self.assertEqual(urlify('ab c'), 'ab%20c')

def test_leading_trailing_spaces(self):
self.assertEqual(urlify(' ab c '), '%20%20ab%20c%20%20')

def test_empty_string(self):
self.assertEqual(urlify(''), '')

def test_no_spaces(self):
self.assertEqual(urlify('abc'), 'abc')

def test_multiple_consecutive_spaces(self):
self.assertEqual(urlify('a b c'), 'a%20%20b%20%20%20c')

def test_special_characters(self):
self.assertEqual(urlify('a b!c'), 'a%20b!c')

def test_mr_john_smith(self):
self.assertEqual(urlify('Mr 3ohn Smith'), 'Mr%203ohn%20Smith')

if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import unittest
from coding.problems.python_solutions.palindrome_permutation import palindrome_permutation

class TestPalindromePermutation(unittest.TestCase):

def test_empty_string(self):
self.assertTrue(palindrome_permutation(""))

def test_single_character(self):
self.assertTrue(palindrome_permutation("a"))

def test_palindrome_odd_length(self):
self.assertTrue(palindrome_permutation("taco cat"))

def test_palindrome_even_length(self):
self.assertTrue(palindrome_permutation("rdeder"))

def test_non_palindrome_odd_length(self):
self.assertFalse(palindrome_permutation("hello"))

def test_non_palindrome_even_length(self):
self.assertFalse(palindrome_permutation("world"))

def test_mixed_case(self):
self.assertTrue(palindrome_permutation("RaceCar"))

def test_numeric_palindrome(self):
self.assertTrue(palindrome_permutation("12321"))

def test_impossible_permutation(self):
self.assertFalse(palindrome_permutation("abcdefg"))

if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ describe("05 - oneAway", () => {
test("Empty and Non-Empty String", () => {
expect(oneAway("", "a")).toEqual(true); // Empty string and a non-empty string
});

});
Loading