Skip to content

Commit 6c1da15

Browse files
Gonzalo Diazsir-gon
authored andcommitted
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Arrays: Array Manipulation. Adjusted the interface to match what hackerrank expects.
1 parent 60a7ee3 commit 6c1da15

File tree

5 files changed

+16
-56
lines changed

5 files changed

+16
-56
lines changed

src/hackerrank/interview_preparation_kit/arrays/cruch_bruteforce.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { logger as console } from '../../../logger';
33

44
import TEST_CASES from './cruch_testcases_test.json';
55

6-
import { arrayManipulation } from './cruch_bruteforce';
6+
import crush from './cruch_bruteforce';
77

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

1212
TEST_CASES.forEach((test) => {
13-
const answer = arrayManipulation(test.n, test.queries);
13+
const answer = crush.arrayManipulation(test.n, test.queries);
1414

1515
console.debug(
1616
`arrayManipulation(${test.n}, ${test.queries.toString()}) solution found: ${answer}`

src/hackerrank/interview_preparation_kit/arrays/cruch_bruteforce.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { logger as console } from '../../../logger';
77

8-
export function arrayManipulation(n: number, queries: number[][]): number {
8+
function arrayManipulation(n: number, queries: number[][]): number {
99
const LENGTH = n + 1;
1010
const SURROGATE_VALUE = 0;
1111
const result: number[] = Array<number>(LENGTH).fill(SURROGATE_VALUE);

src/hackerrank/interview_preparation_kit/arrays/cruch_optimized.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { logger as console } from '../../../logger';
33

44
import TEST_CASES from './cruch_testcases_test.json';
55

6-
import { arrayManipulation } from './cruch_optimized';
6+
import crush from './cruch_optimized';
77

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

1212
TEST_CASES.forEach((test) => {
13-
const answer = arrayManipulation(test.n, test.queries);
13+
const answer = crush.arrayManipulation(test.n, test.queries);
1414

1515
console.debug(
1616
`arrayManipulation(${test.n}, ${test.queries.toString()}) solution found: ${answer}`

src/hackerrank/interview_preparation_kit/arrays/cruch_optimized.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @link Problem definition [[docs/hackerrank/interview_preparation_kit/arrays/crush.md]]
33
*/
44

5-
export function arrayManipulation(n: number, queries: number[][]): number {
5+
function arrayManipulation(n: number, queries: number[][]): number {
66
// why adding 2?
77
// first slot to adjust 1-based index and
88
// last slot for storing accumSum result

src/hackerrank/interview_preparation_kit/arrays/cruch_testcases_test.json

Lines changed: 10 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,70 +3,30 @@
33
"title": "Sample Test Case 0",
44
"n": 5,
55
"queries": [
6-
[
7-
1,
8-
2,
9-
100
10-
],
11-
[
12-
2,
13-
5,
14-
100
15-
],
16-
[
17-
3,
18-
4,
19-
100
20-
]
6+
[1, 2, 100],
7+
[2, 5, 100],
8+
[3, 4, 100]
219
],
2210
"expected": 200
2311
},
2412
{
2513
"title": "Sample Test Case 1",
2614
"n": 10,
2715
"queries": [
28-
[
29-
1,
30-
5,
31-
3
32-
],
33-
[
34-
4,
35-
8,
36-
7
37-
],
38-
[
39-
6,
40-
9,
41-
1
42-
]
16+
[1, 5, 3],
17+
[4, 8, 7],
18+
[6, 9, 1]
4319
],
4420
"expected": 10
4521
},
4622
{
4723
"title": "Sample Test Case 3",
4824
"n": 10,
4925
"queries": [
50-
[
51-
2,
52-
6,
53-
8
54-
],
55-
[
56-
3,
57-
5,
58-
7
59-
],
60-
[
61-
1,
62-
8,
63-
1
64-
],
65-
[
66-
5,
67-
9,
68-
15
69-
]
26+
[2, 6, 8],
27+
[3, 5, 7],
28+
[1, 8, 1],
29+
[5, 9, 15]
7030
],
7131
"expected": 31
7232
}

0 commit comments

Comments
 (0)