diff --git a/src/hackerrank/interview_preparation_kit/arrays/2d_array.test.ts b/src/hackerrank/interview_preparation_kit/arrays/2d_array.test.ts index b72689d8..cc0e6a22 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/2d_array.test.ts +++ b/src/hackerrank/interview_preparation_kit/arrays/2d_array.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from '@jest/globals'; import { logger as console } from '../../../logger'; -import { hourglassSum } from './2d_array'; +import twoDarray from './2d_array'; import TEST_CASES from './2d_array.testcases_test.json'; describe('arrays: 2d Array hourglassSum', () => { @@ -9,7 +9,7 @@ describe('arrays: 2d Array hourglassSum', () => { expect.assertions(3); TEST_CASES.forEach((test) => { - const answer = hourglassSum(test.input); + const answer = twoDarray.hourglassSum(test.input); console.debug( `gethourGlass(${test.input.toString()}) solution found: ${answer}` diff --git a/src/hackerrank/interview_preparation_kit/arrays/2d_array.ts b/src/hackerrank/interview_preparation_kit/arrays/2d_array.ts index 333e404c..c06fd9cb 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/2d_array.ts +++ b/src/hackerrank/interview_preparation_kit/arrays/2d_array.ts @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/interview_preparation_kit/arrays/2d_array.md]] */ -export function gethourGlass( +function gethourGlass( arr: number[][], positionX: number, positionY: number @@ -22,7 +22,7 @@ export function gethourGlass( return result; } -export function hourglassSum(arr: number[][]): number | null { +function hourglassSum(arr: number[][]): number | null { let matrixSize = 0; if (arr?.[0]) { diff --git a/src/hackerrank/interview_preparation_kit/arrays/cruch_bruteforce.test.ts b/src/hackerrank/interview_preparation_kit/arrays/cruch_bruteforce.test.ts index 33c27fe7..2ccc4943 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/cruch_bruteforce.test.ts +++ b/src/hackerrank/interview_preparation_kit/arrays/cruch_bruteforce.test.ts @@ -3,14 +3,14 @@ import { logger as console } from '../../../logger'; import TEST_CASES from './cruch_testcases_test.json'; -import { arrayManipulation } from './cruch_bruteforce'; +import crush from './cruch_bruteforce'; describe('arrays: crush (bruteforce) small cases', () => { it('arrayManipulation Test Cases', () => { expect.assertions(3); TEST_CASES.forEach((test) => { - const answer = arrayManipulation(test.n, test.queries); + const answer = crush.arrayManipulation(test.n, test.queries); console.debug( `arrayManipulation(${test.n}, ${test.queries.toString()}) solution found: ${answer}` diff --git a/src/hackerrank/interview_preparation_kit/arrays/cruch_bruteforce.ts b/src/hackerrank/interview_preparation_kit/arrays/cruch_bruteforce.ts index 4ebdf654..86fe2ba8 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/cruch_bruteforce.ts +++ b/src/hackerrank/interview_preparation_kit/arrays/cruch_bruteforce.ts @@ -5,7 +5,7 @@ import { logger as console } from '../../../logger'; -export function arrayManipulation(n: number, queries: number[][]): number { +function arrayManipulation(n: number, queries: number[][]): number { const LENGTH = n + 1; const SURROGATE_VALUE = 0; const result: number[] = Array(LENGTH).fill(SURROGATE_VALUE); diff --git a/src/hackerrank/interview_preparation_kit/arrays/cruch_optimized.test.ts b/src/hackerrank/interview_preparation_kit/arrays/cruch_optimized.test.ts index da06999c..b0491367 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/cruch_optimized.test.ts +++ b/src/hackerrank/interview_preparation_kit/arrays/cruch_optimized.test.ts @@ -3,14 +3,14 @@ import { logger as console } from '../../../logger'; import TEST_CASES from './cruch_testcases_test.json'; -import { arrayManipulation } from './cruch_optimized'; +import crush from './cruch_optimized'; describe('arrays: crush (optimized)', () => { it('arrayManipulation Test Cases', () => { expect.assertions(3); TEST_CASES.forEach((test) => { - const answer = arrayManipulation(test.n, test.queries); + const answer = crush.arrayManipulation(test.n, test.queries); console.debug( `arrayManipulation(${test.n}, ${test.queries.toString()}) solution found: ${answer}` diff --git a/src/hackerrank/interview_preparation_kit/arrays/cruch_optimized.ts b/src/hackerrank/interview_preparation_kit/arrays/cruch_optimized.ts index a95f77db..ee8f7c8f 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/cruch_optimized.ts +++ b/src/hackerrank/interview_preparation_kit/arrays/cruch_optimized.ts @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/interview_preparation_kit/arrays/crush.md]] */ -export function arrayManipulation(n: number, queries: number[][]): number { +function arrayManipulation(n: number, queries: number[][]): number { // why adding 2? // first slot to adjust 1-based index and // last slot for storing accumSum result diff --git a/src/hackerrank/interview_preparation_kit/arrays/cruch_testcases_test.json b/src/hackerrank/interview_preparation_kit/arrays/cruch_testcases_test.json index ec7d19ca..fa4f8a1d 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/cruch_testcases_test.json +++ b/src/hackerrank/interview_preparation_kit/arrays/cruch_testcases_test.json @@ -3,21 +3,9 @@ "title": "Sample Test Case 0", "n": 5, "queries": [ - [ - 1, - 2, - 100 - ], - [ - 2, - 5, - 100 - ], - [ - 3, - 4, - 100 - ] + [1, 2, 100], + [2, 5, 100], + [3, 4, 100] ], "expected": 200 }, @@ -25,21 +13,9 @@ "title": "Sample Test Case 1", "n": 10, "queries": [ - [ - 1, - 5, - 3 - ], - [ - 4, - 8, - 7 - ], - [ - 6, - 9, - 1 - ] + [1, 5, 3], + [4, 8, 7], + [6, 9, 1] ], "expected": 10 }, @@ -47,26 +23,10 @@ "title": "Sample Test Case 3", "n": 10, "queries": [ - [ - 2, - 6, - 8 - ], - [ - 3, - 5, - 7 - ], - [ - 1, - 8, - 1 - ], - [ - 5, - 9, - 15 - ] + [2, 6, 8], + [3, 5, 7], + [1, 8, 1], + [5, 9, 15] ], "expected": 31 } diff --git a/src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.test.ts b/src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.test.ts index b47a9fec..36475a91 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.test.ts +++ b/src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.test.ts @@ -1,41 +1,34 @@ import { describe, expect, it } from '@jest/globals'; import { logger as console } from '../../../logger'; -import { rotLeft, rotLeftOne } from './ctci_array_left_rotation'; +import arrayLeftRotation from './ctci_array_left_rotation'; -import ROT_LEFT_ONE_TEST_CASES from './ctci_array_left_rotation.testcases.json'; +import ROT_LEFT_TEST_CASES from './ctci_array_left_rotation.testcases.json'; -describe('ctci_array_left_rotation', () => { - it('rotLeftOne Test Cases', () => { - expect.assertions(5); - - ROT_LEFT_ONE_TEST_CASES.forEach((test) => { - const input = test.numbers; - const answer = rotLeftOne(input); - - console.debug( - `rotLeftOne(${test.numbers.toString()}) solution found: ${answer.toString()}` - ); +interface RotLeftTestCase { + title: string; + input: number[]; + d_rotations: number; + expected: number[]; +} - expect(answer).toStrictEqual(test.expected); - }); - }); +const TEST_CASES: RotLeftTestCase[] = ROT_LEFT_TEST_CASES as RotLeftTestCase[]; +describe('ctci_array_left_rotation', () => { it('rotLeft Test cases', () => { - expect.assertions(1); + expect.assertions(8); - const ROT_LEFT_TEST_CASES = [ - { numbers: [1, 2, 3, 4, 5], d_rotations: 4, expected: [5, 1, 2, 3, 4] } - ]; - - ROT_LEFT_TEST_CASES.forEach((value) => { - const answer = rotLeft(value.numbers, value.d_rotations); + TEST_CASES.forEach((test: RotLeftTestCase) => { + const answer = arrayLeftRotation.rotLeft( + test.input, + Number(test.d_rotations) + ); console.debug( - `rotLeft(${value.numbers.toString()}) solution found: ${answer.toString()}` + `rotLeft(${test.input.toString()}) solution found: ${test.expected.toString()}` ); - expect(answer).toStrictEqual(value.expected); + expect(answer).toStrictEqual(test.expected); }); }); }); diff --git a/src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.testcases.json b/src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.testcases.json index aa06f8ae..086230cf 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.testcases.json +++ b/src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.testcases.json @@ -1,7 +1,10 @@ [ - {"numbers": [1, 2, 3, 4, 5], "expected": [2, 3, 4, 5, 1]}, - {"numbers": [2, 3, 4, 5, 1], "expected": [3, 4, 5, 1, 2]}, - {"numbers": [3, 4, 5, 1, 2], "expected": [4, 5, 1, 2, 3]}, - {"numbers": [4, 5, 1, 2, 3], "expected": [5, 1, 2, 3, 4]}, - {"numbers": [5, 1, 2, 3, 4], "expected": [1, 2, 3, 4, 5]} + {"title": "Own 0", "input": [1, 2, 3, 4, 5], "d_rotations": 1, "expected": [2, 3, 4, 5, 1]}, + {"title": "Own 1", "input": [2, 3, 4, 5, 1], "d_rotations": 1, "expected": [3, 4, 5, 1, 2]}, + {"title": "Own 2", "input": [3, 4, 5, 1, 2], "d_rotations": 1, "expected": [4, 5, 1, 2, 3]}, + {"title": "Own 3", "input": [4, 5, 1, 2, 3], "d_rotations": 1, "expected": [5, 1, 2, 3, 4]}, + {"title": "Own 4", "input": [5, 1, 2, 3, 4], "d_rotations": 1, "expected": [1, 2, 3, 4, 5]}, + {"title": "Sample Test case 0", "input": [1, 2, 3, 4, 5], "d_rotations": 4, "expected": [5, 1, 2, 3, 4]}, + {"title": "Sample Test case 1", "input": [41, 73, 89, 7, 10, 1, 59, 58, 84, 77, 77, 97, 58, 1, 86, 58, 26, 10, 86, 51], "d_rotations": 10, "expected": [77, 97, 58, 1, 86, 58, 26, 10, 86, 51, 41, 73, 89, 7, 10, 1, 59, 58, 84, 77]}, + {"title": "Sample Test case 1", "input": [33, 47, 70, 37, 8, 53, 13, 93, 71, 72, 51, 100, 60, 87, 97], "d_rotations": 13, "expected": [87, 97, 33, 47, 70, 37, 8, 53, 13, 93, 71, 72, 51, 100, 60]} ] diff --git a/src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.ts b/src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.ts index b60de67e..6376d2e6 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.ts +++ b/src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.ts @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.md]] */ -export function rotLeftOne(aNumbers: number[]): number[] { +function rotLeftOne(aNumbers: number[]): number[] { const first = aNumbers.shift(); if (first !== undefined) { aNumbers.push(first); @@ -11,7 +11,7 @@ export function rotLeftOne(aNumbers: number[]): number[] { return aNumbers; } -export function rotLeft(aNumbers: number[], dRotations: number): number[] { +function rotLeft(aNumbers: number[], dRotations: number): number[] { let output = [...aNumbers]; for (let i = 0; i < dRotations; i++) { diff --git a/src/hackerrank/interview_preparation_kit/arrays/minimum_swaps_2.test.ts b/src/hackerrank/interview_preparation_kit/arrays/minimum_swaps_2.test.ts index 1b91aaf9..a6088b3c 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/minimum_swaps_2.test.ts +++ b/src/hackerrank/interview_preparation_kit/arrays/minimum_swaps_2.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from '@jest/globals'; import { logger as console } from '../../../logger'; -import { minimumSwaps } from './minimum_swaps_2'; +import ms2 from './minimum_swaps_2'; import TEST_CASES from './minimum_swaps_2.testcases.json'; @@ -10,7 +10,7 @@ describe('minimum swaps 2', () => { expect.assertions(3); TEST_CASES.forEach((test) => { - const answer = minimumSwaps(test.input); + const answer = ms2.minimumSwaps(test.input); console.debug( `minimumSwaps(${test.input.toString()}) solution found: ${answer}` diff --git a/src/hackerrank/interview_preparation_kit/arrays/minimum_swaps_2.ts b/src/hackerrank/interview_preparation_kit/arrays/minimum_swaps_2.ts index 81f3113c..11f65926 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/minimum_swaps_2.ts +++ b/src/hackerrank/interview_preparation_kit/arrays/minimum_swaps_2.ts @@ -2,7 +2,7 @@ * @link Problem definition [[docs/hackerrank/interview_preparation_kit/arrays/minimum_swaps_2.md]] */ -export function minimumSwaps(arr: number[]): number { +function minimumSwaps(arr: number[]): number { const indexedGroup = arr.map((x) => x - 1); let swaps = 0; let index = 0; diff --git a/src/hackerrank/interview_preparation_kit/arrays/new_year_chaos.test.ts b/src/hackerrank/interview_preparation_kit/arrays/new_year_chaos.test.ts index 3c708d9e..fd043c27 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/new_year_chaos.test.ts +++ b/src/hackerrank/interview_preparation_kit/arrays/new_year_chaos.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from '@jest/globals'; import { logger as console } from '../../../logger'; -import { minimumBribesTransform } from './new_year_chaos'; +import nyc from './new_year_chaos'; import TEST_CASES from './new_year_chaos.testcases.json'; @@ -10,7 +10,8 @@ describe('new_year_chaos', () => { expect.assertions(5); TEST_CASES.forEach((value) => { - const answer = minimumBribesTransform(value.input); + const answer = nyc.minimumBribesText(value.input); + nyc.minimumBribes(value.input); console.debug( `minimumBribesTransform(${value.input.toString()}) solution found: ${answer}` diff --git a/src/hackerrank/interview_preparation_kit/arrays/new_year_chaos.testcases.json b/src/hackerrank/interview_preparation_kit/arrays/new_year_chaos.testcases.json index 5527c31e..1679946f 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/new_year_chaos.testcases.json +++ b/src/hackerrank/interview_preparation_kit/arrays/new_year_chaos.testcases.json @@ -1,27 +1,27 @@ [ - { - "title": "Test Case 0-0", - "input": [2, 1, 5, 3, 4], - "expected": 3 - }, - { - "title": "Test Case 0-1", - "input": [2, 5, 1, 3, 4], - "expected": "Too chaotic" - }, - { - "title": "Test Case 1-1", - "input": [5, 1, 2, 3, 7, 8, 6, 4], - "expected": "Too chaotic" - }, - { - "title": "Test Case 1-2", - "input": [1, 2, 5, 3, 7, 8, 6, 4], - "expected": 7 - }, - { - "title": "Test Case 2", - "input": [1, 2, 5, 3, 4, 7, 8, 6], - "expected": 4 - } - ] + { + "title": "Test Case 0-0", + "input": [2, 1, 5, 3, 4], + "expected": "3" + }, + { + "title": "Test Case 0-1", + "input": [2, 5, 1, 3, 4], + "expected": "Too chaotic" + }, + { + "title": "Test Case 1-1", + "input": [5, 1, 2, 3, 7, 8, 6, 4], + "expected": "Too chaotic" + }, + { + "title": "Test Case 1-2", + "input": [1, 2, 5, 3, 7, 8, 6, 4], + "expected": "7" + }, + { + "title": "Test Case 2", + "input": [1, 2, 5, 3, 4, 7, 8, 6], + "expected": "4" + } +] diff --git a/src/hackerrank/interview_preparation_kit/arrays/new_year_chaos.ts b/src/hackerrank/interview_preparation_kit/arrays/new_year_chaos.ts index b8b39046..2d6c3c4c 100644 --- a/src/hackerrank/interview_preparation_kit/arrays/new_year_chaos.ts +++ b/src/hackerrank/interview_preparation_kit/arrays/new_year_chaos.ts @@ -2,10 +2,10 @@ * @link Problem definition [[docs/hackerrank/interview_preparation_kit/arrays/new_year_chaos.md]] */ -export const TOO_CHAOTIC_ERROR = 'Too chaotic'; -export const NEW_YEAR_CHAOS_TOLERANCE = 2; +const TOO_CHAOTIC_ERROR = 'Too chaotic'; +const NEW_YEAR_CHAOS_TOLERANCE = 2; -export function minimumBribes(q: number[]): number { +function minimumBribesCalculate(q: number[]): number { let bribes = 0; let i = 0; @@ -15,7 +15,10 @@ export function minimumBribes(q: number[]): number { throw new Error(TOO_CHAOTIC_ERROR); } - const fragment = q.slice(Math.max(value - NEW_YEAR_CHAOS_TOLERANCE, 0), i); + const fragment = q.slice( + Math.min(Math.max(value - NEW_YEAR_CHAOS_TOLERANCE, 0), i), + i + ); fragment.forEach((k) => { if (k > value) { @@ -28,11 +31,11 @@ export function minimumBribes(q: number[]): number { return bribes; } -export function minimumBribesTransform(queue: number[]): number | string { - let result: number | string = ''; +function minimumBribesText(queue: number[]): string { + let result = ''; try { - result = minimumBribes(queue); + result = `${minimumBribesCalculate(queue)}`; } catch (err: unknown) { if (err instanceof Error) { result = err.message; @@ -42,4 +45,8 @@ export function minimumBribesTransform(queue: number[]): number | string { return result; } -export default { minimumBribes, minimumBribesTransform, TOO_CHAOTIC_ERROR }; +function minimumBribes(q: number[]): void { + console.log(minimumBribesText(q)); +} + +export default { minimumBribes, minimumBribesText, TOO_CHAOTIC_ERROR }; diff --git a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_bruteforce.test.ts b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_bruteforce.test.ts index 2705b840..dc910fb9 100644 --- a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_bruteforce.test.ts +++ b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_bruteforce.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from '@jest/globals'; import { logger as console } from '../../../logger'; -import { countTriplets } from './count_triplets_1_bruteforce'; +import CountTriplets from './count_triplets_1_bruteforce'; import SMALL_TEST_CASES from './count_triplets_1.small.testcases.json'; @@ -10,7 +10,7 @@ describe('count_triplets_1', () => { expect.assertions(4); SMALL_TEST_CASES.forEach((test) => { - const answer = countTriplets(test.input, test.r); + const answer = CountTriplets.countTriplets(test.input, test.r); console.debug( `countTriplets(${test.input.toString()}, ${test.r}) solution found: ${answer}` diff --git a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_bruteforce.ts b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_bruteforce.ts index ffc33a2c..40780981 100644 --- a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_bruteforce.ts +++ b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_bruteforce.ts @@ -4,7 +4,7 @@ */ import { logger as console } from '../../../logger'; -export function countTriplets(arr: number[], ratio: number): number { +function countTriplets(arr: number[], ratio: number): number { const size = arr.length; let counter = 0; diff --git a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_optimized.test.ts b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_optimized.test.ts index ee82d24c..6d3676ed 100644 --- a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_optimized.test.ts +++ b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_optimized.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from '@jest/globals'; import { logger as console } from '../../../logger'; -import { countTriplets } from './count_triplets_1_optmized'; +import CountTriplets from './count_triplets_1_optmized'; import SMALL_TEST_CASES from './count_triplets_1.small.testcases.json'; import BIG_TEST_CASES from './count_triplets_1.big.testcases.json'; @@ -11,7 +11,7 @@ describe('count_triplets_1 (optimized)', () => { expect.assertions(4); SMALL_TEST_CASES.forEach((test) => { - const answer = countTriplets(test.input, test.r); + const answer = CountTriplets.countTriplets(test.input, test.r); console.debug( `countTriplets(${test.input.toString()}, ${test.r}) solution found: ${answer}` @@ -25,7 +25,7 @@ describe('count_triplets_1 (optimized)', () => { expect.assertions(1); BIG_TEST_CASES.forEach((test) => { - const answer = countTriplets(test.input, test.r); + const answer = CountTriplets.countTriplets(test.input, test.r); console.debug( `countTriplets(${test.input.toString()}, ${test.r}) solution found: ${answer}` diff --git a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_optmized.ts b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_optmized.ts index 277a80aa..a20ea6fe 100644 --- a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_optmized.ts +++ b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_optmized.ts @@ -3,7 +3,7 @@ * @see Solution Notes: [[docs/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1-solution-notes.md]] */ -export function countTriplets(arr: number[], ratio: number): number { +function countTriplets(arr: number[], ratio: number): number { let triplets = 0; const aCounter: Record = arr.reduce( diff --git a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.test.ts b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.test.ts index 2a7b1447..0f113c7c 100644 --- a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.test.ts +++ b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from '@jest/globals'; import { logger as console } from '../../../logger'; -import { twoStrings } from './two_strings'; +import twoStrings from './two_strings'; import TEST_CASES from './two_strings.testcases.json'; @@ -11,7 +11,7 @@ describe('two_strings', () => { TEST_CASES.forEach((testCase) => { testCase?.test.forEach((test) => { - const answer = twoStrings(test.s1, test.s2); + const answer = twoStrings.twoStrings(test.s1, test.s2); console.debug( `twoStrings(${test.s1}, ${test.s2}) solution found: ${answer}` diff --git a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.ts b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.ts index 878e7caa..e7123698 100644 --- a/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.ts +++ b/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.ts @@ -5,7 +5,7 @@ const __YES__ = 'YES'; const __NO__ = 'NO'; -export function twoStringsCompute(s1: string, s2: string): boolean { +function twoStringsCompute(s1: string, s2: string): boolean { for (const char of s1) { if (s2.includes(char)) { return true; @@ -14,7 +14,7 @@ export function twoStringsCompute(s1: string, s2: string): boolean { return false; } -export function twoStrings(s1: string, s2: string): string { +function twoStrings(s1: string, s2: string): string { return twoStringsCompute(s1, s2) ? __YES__ : __NO__; }