Skip to content

Refactor #653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 35 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5f6d8fe
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Array: 2D Array -…
sir-gon Mar 10, 2025
36980f3
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Arrays: Minimum S…
Feb 20, 2025
3e4349f
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Arrays: Array Man…
sir-gon Mar 10, 2025
1274bc4
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Arrays: Left Rota…
Feb 20, 2025
81f668f
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Arrays: New Year …
sir-gon Mar 10, 2025
9613214
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Dictionaries and …
sir-gon Mar 10, 2025
23f76fa
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Dictionaries and …
Feb 21, 2025
c46c3d1
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Dictionaries and …
sir-gon Mar 5, 2025
b5fd4d9
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Dictionaries and …
sir-gon Mar 5, 2025
1473855
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Dictionaries and …
sir-gon Mar 10, 2025
8a75490
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Dynamic Programmi…
sir-gon Mar 10, 2025
07ba9f7
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Greedy Algorithms…
sir-gon Mar 5, 2025
67e2b99
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Greedy Algorithms…
sir-gon Mar 10, 2025
bd06f35
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Greedy Algorithms…
sir-gon Mar 10, 2025
bee3ef0
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Greedy Algorithms…
sir-gon Mar 10, 2025
c65fa06
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Miscellaneous: Fl…
sir-gon Mar 10, 2025
f052d74
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Miscellaneous: Fr…
sir-gon Mar 10, 2025
923798c
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Recursion: Fibona…
sir-gon Mar 10, 2025
6519af0
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Recursion: Davis'…
sir-gon Mar 10, 2025
b602195
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Recursion: Recurs…
sir-gon Mar 12, 2025
ca165fb
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Hash Tables: Ice …
sir-gon Mar 12, 2025
45e92eb
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Search: Swap Node…
sir-gon Mar 12, 2025
cfc260d
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Sorting: Bubble S…
sir-gon Mar 12, 2025
838b71b
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Sorting: Comparator.
sir-gon Mar 12, 2025
9678697
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Sorting: Mark and…
sir-gon Mar 12, 2025
661aef5
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Stacks and Queues…
sir-gon Mar 12, 2025
1e41bb6
[REFACTOR] [Hacker Rank] Interview Preparation Kit: String Manipulati…
sir-gon Mar 12, 2025
8cef7ff
[REFACTOR] [Hacker Rank] Interview Preparation Kit: String Manipulati…
sir-gon Mar 12, 2025
456520e
[REFACTOR] [Hacker Rank] Interview Preparation Kit: String Manipulati…
Mar 13, 2025
bc1f552
[REFACTOR] root examples.
Mar 13, 2025
3c35df8
[REFACTOR] projecteuler exercises.
Mar 13, 2025
f571c9b
[REFACTOR] [Hacker Rank] warmup exercises.
Mar 13, 2025
c5686c2
[REFACTOR] [Hacker Rank] implementation exercises.
Mar 13, 2025
9e1ad63
[REFACTOR] [Hacker Rank] projecteuler exercises.
Mar 13, 2025
3091442
[REFACTOR] [Hacker Rank] libraries.
Mar 13, 2025
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
9 changes: 5 additions & 4 deletions src/hackerrank/implementation/betweenTwoSets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @link Problem definition [[docs/hackerrank/implementation/betweenTwoSets.md]]
*/

export function isFactor(n, group) {
function isFactor(n, group) {
let result = true;
let i = 0;

Expand All @@ -19,7 +19,7 @@ export function isFactor(n, group) {
return result;
}

export function factorOf(n, group) {
function factorOf(n, group) {
let result = true;
let i = 0;

Expand All @@ -36,7 +36,7 @@ export function factorOf(n, group) {
return result;
}

export function getTotalX(a, b) {
function getTotalX(a, b) {
let max = 0;
for (const j of b) {
if (j > max) max = j;
Expand All @@ -53,4 +53,5 @@ export function getTotalX(a, b) {
return result.length;
}

export default { getTotalX };
export default { getTotalX, isFactor, factorOf };
export { getTotalX, isFactor, factorOf };
3 changes: 2 additions & 1 deletion src/hackerrank/implementation/birthday.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { logger as console } from '../../logger.js';

export function birthday(s, d, m) {
function birthday(s, d, m) {
let result = 0;
console.debug(`s: ${s}`);

Expand All @@ -23,3 +23,4 @@ export function birthday(s, d, m) {
}

export default { birthday };
export { birthday };
3 changes: 2 additions & 1 deletion src/hackerrank/implementation/bonAppetit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { logger as console } from '../../logger.js';

export function bonAppetit(bill, k, b) {
function bonAppetit(bill, k, b) {
const totalSum = bill.reduce(
(previousValue, currentValue) => previousValue + currentValue,
0
Expand All @@ -25,3 +25,4 @@ export function bonAppetit(bill, k, b) {
}

export default { bonAppetit };
export { bonAppetit };
3 changes: 2 additions & 1 deletion src/hackerrank/implementation/breakingRecords.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @link Problem definition [[docs/hackerrank/implementation/breakingRecords.md]]
*/

export function breakingRecords(scores) {
function breakingRecords(scores) {
if (scores.length === 0) {
throw new Error('Empty input');
}
Expand All @@ -29,3 +29,4 @@ export function breakingRecords(scores) {
}

export default { breakingRecords };
export { breakingRecords };
3 changes: 2 additions & 1 deletion src/hackerrank/implementation/countApplesAndOranges.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @link Problem definition [[docs/hackerrank/implementation/countApplesAndOranges.md]]
*/

export function countApplesAndOranges(s, t, a, b, apples, oranges) {
function countApplesAndOranges(s, t, a, b, apples, oranges) {
let cApples = 0;
let cOranges = 0;

Expand All @@ -26,3 +26,4 @@ export function countApplesAndOranges(s, t, a, b, apples, oranges) {
}

export default { countApplesAndOranges };
export { countApplesAndOranges };
3 changes: 2 additions & 1 deletion src/hackerrank/implementation/countingValleys.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { logger as console } from '../../logger.js';

export function countingValleys(steps, path) {
function countingValleys(steps, path) {
const stepList = path.split('');
let altitude = 0;
let valleys = 0;
Expand All @@ -27,3 +27,4 @@ export function countingValleys(steps, path) {
}

export default { countingValleys };
export { countingValleys };
3 changes: 2 additions & 1 deletion src/hackerrank/implementation/dayOfProgrammer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { daysInMonthNumber } from '../../constants/index.js';

const zeroPad = (num, places) => String(num).padStart(places, '0');

export function dayOfProgrammer(year) {
function dayOfProgrammer(year) {
const dayToSearch = 256;
let leap;

Expand Down Expand Up @@ -51,3 +51,4 @@ export function dayOfProgrammer(year) {
}

export default { dayOfProgrammer };
export { dayOfProgrammer };
3 changes: 2 additions & 1 deletion src/hackerrank/implementation/divisibleSumPairs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { logger as console } from '../../logger.js';

export function divisibleSumPairs(n, k, ar) {
function divisibleSumPairs(n, k, ar) {
let pairs = 0;
for (let i = 0; i < ar.length; i++) {
for (let j = i + 1; j < ar.length; j++) {
Expand All @@ -19,3 +19,4 @@ export function divisibleSumPairs(n, k, ar) {
}

export default { divisibleSumPairs };
export { divisibleSumPairs };
3 changes: 2 additions & 1 deletion src/hackerrank/implementation/gradingStudents.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @link Problem definition [[docs/hackerrank/implementation/gradingStudents.md]]
*/

export function gradingStudents(grades) {
function gradingStudents(grades) {
const minimum = 38;
const roundTo = 5;
const result = [];
Expand All @@ -23,3 +23,4 @@ export function gradingStudents(grades) {
}

export default { gradingStudents };
export { gradingStudents };
3 changes: 2 additions & 1 deletion src/hackerrank/implementation/jumpingOnClouds.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { logger as console } from '../../logger.js';

export function jumpingOnClouds(c) {
function jumpingOnClouds(c) {
let result = 0;
let key = 0;

Expand All @@ -26,3 +26,4 @@ export function jumpingOnClouds(c) {
}

export default { jumpingOnClouds };
export { jumpingOnClouds };
3 changes: 2 additions & 1 deletion src/hackerrank/implementation/kangaroo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @link Problem definition [[docs/hackerrank/implementation/kangaroo.md]]
*/

export function kangaroo(x1, v1, x2, v2) {
function kangaroo(x1, v1, x2, v2) {
if (v1 === v2) {
if (x1 !== x2) return 'NO';
return 'YES';
Expand All @@ -18,3 +18,4 @@ export function kangaroo(x1, v1, x2, v2) {
}

export default { kangaroo };
export { kangaroo };
3 changes: 2 additions & 1 deletion src/hackerrank/implementation/migratoryBirds.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import util from 'util';
import { logger as console } from '../../logger.js';

export function migratoryBirds(arr) {
function migratoryBirds(arr) {
if (arr.length === 0) {
throw new Error('Empty input');
}
Expand Down Expand Up @@ -35,3 +35,4 @@ export function migratoryBirds(arr) {
}

export default { migratoryBirds };
export { migratoryBirds };
3 changes: 2 additions & 1 deletion src/hackerrank/implementation/minimumAbsoluteDifference.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { logger as console } from '../../logger.js';

export function minimumAbsoluteDifference(arr) {
function minimumAbsoluteDifference(arr) {
if (arr.length === 0) {
throw new Error('Empty input');
}
Expand All @@ -31,3 +31,4 @@ export function minimumAbsoluteDifference(arr) {
}

export default { minimumAbsoluteDifference };
export { minimumAbsoluteDifference };
7 changes: 4 additions & 3 deletions src/hackerrank/implementation/repeatedString.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { logger as console } from '../../logger.js';

export function countAs(word) {
function countAs(word) {
let result = 0;

const chars = word.split('');
Expand All @@ -18,7 +18,7 @@ export function countAs(word) {
return result;
}

export function repeatedString(s, n) {
function repeatedString(s, n) {
let result = 0;

const blockSize = s.length;
Expand All @@ -32,4 +32,5 @@ export function repeatedString(s, n) {
return result;
}

export default { countAs };
export default { repeatedString };
export { repeatedString };
3 changes: 2 additions & 1 deletion src/hackerrank/implementation/sockMerchant.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { logger as console } from '../../logger.js';

export function sockMerchant(n, ar) {
function sockMerchant(n, ar) {
let result = 0;

const matches = {};
Expand All @@ -25,3 +25,4 @@ export function sockMerchant(n, ar) {
}

export default { sockMerchant };
export { sockMerchant };
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ function hourglassSum(arr) {
}

export default { hourglassSum };
export { hourglassSum };
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { describe, expect, it } from '@jest/globals';
import { logger as console } from '../../../logger.js';

import twoDArray from './2d_array.js';
import { hourglassSum } from './2d_array.js';
import TEST_CASES from './2d_array.testcases_test.json';

describe('arrays: 2d Array hourglassSum', () => {
it('hourglassSum Test Cases', () => {
expect.assertions(3);

TEST_CASES.forEach((test) => {
const answer = twoDArray.hourglassSum(test.input);
const answer = hourglassSum(test.input);

console.debug(
`gethourGlass(${test.input.toString()}) solution found: ${answer}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ function arrayManipulation(n, queries) {
}

export default { arrayManipulation };
export { arrayManipulation };
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { logger as console } from '../../../logger.js';

import TEST_CASES from './cruch_testcases_test.json';

import crush from './cruch_bruteforce.js';
import { arrayManipulation } from './cruch_bruteforce.js';

describe('arrays: crush (bruteforce) small cases', () => {
it('arrayManipulation Test Cases', () => {
expect.assertions(3);

TEST_CASES.forEach((test) => {
const answer = crush.arrayManipulation(test.n, test.queries);
const answer = arrayManipulation(test.n, test.queries);

console.debug(
`arrayManipulation(${test.n}, ${test.queries}) solution found: ${answer}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ function arrayManipulation(n, queries) {
}

export default { arrayManipulation };
export { arrayManipulation };
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { logger as console } from '../../../logger.js';

import TEST_CASES from './cruch_testcases_test.json';

import crush from './cruch_optimized.js';
import { arrayManipulation } from './cruch_optimized.js';

describe('arrays: crush (optimized)', () => {
it('arrayManipulation Test Cases', () => {
expect.assertions(3);

TEST_CASES.forEach((test) => {
const answer = crush.arrayManipulation(test.n, test.queries);
const answer = arrayManipulation(test.n, test.queries);

console.debug(
`arrayManipulation(${test.n}, ${test.queries}) solution found: ${answer}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @link Problem definition [[docs/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.md]]
*/

export function rotLeftOne(aNumbers) {
function rotLeftOne(aNumbers) {
const first = aNumbers.shift();
if (first !== undefined) {
aNumbers.push(first);
Expand All @@ -11,7 +11,7 @@ export function rotLeftOne(aNumbers) {
return aNumbers;
}

export function rotLeft(aNumbers, dRotations) {
function rotLeft(aNumbers, dRotations) {
let output = [...aNumbers];

for (let i = 0; i < dRotations; i++) {
Expand All @@ -22,3 +22,4 @@ export function rotLeft(aNumbers, dRotations) {
}

export default { rotLeft, rotLeftOne };
export { rotLeft };
Original file line number Diff line number Diff line change
@@ -1,42 +1,20 @@
import { describe, expect, it } from '@jest/globals';
import { logger as console } from '../../../logger.js';

import { rotLeft, rotLeftOne } from './ctci_array_left_rotation.js';
import { rotLeft } from './ctci_array_left_rotation.js';

const ROT_LEFT_ONE_TEST_CASES = [
{ 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] }
];

const ROT_LEFT_TEST_CASES = [
{ numbers: [1, 2, 3, 4, 5], d_rotations: 4, expected: [5, 1, 2, 3, 4] }
];
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((value) => {
const answer = rotLeftOne(value.numbers);

console.debug(`rotLeftOne(${value.numbers}) solution found: ${answer}`);

expect(answer).toStrictEqual(value.expected);
});
});

it('rotLeft Test cases', () => {
expect.assertions(1);
expect.assertions(8);

ROT_LEFT_TEST_CASES.forEach((value) => {
const answer = rotLeft(value.numbers, value.d_rotations);
ROT_LEFT_TEST_CASES.forEach((test) => {
const answer = rotLeft(test.input, test.d_rotations);

console.debug(`rotLeft(${value.numbers}) solution found: ${answer}`);
console.debug(`rotLeft(${test.numbers}) solution found: ${answer}`);

expect(answer).toStrictEqual(value.expected);
expect(answer).toStrictEqual(test.expected);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{"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 2", "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]}
]
Loading