Skip to content

Commit 80f5379

Browse files
committed
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Dictionaries and Hashmaps: Count Triplets.
* TEST data moved to JSON. * Adjusted the interface to match what hackerrank expects.
1 parent c3394e8 commit 80f5379

File tree

6 files changed

+19
-43
lines changed

6 files changed

+19
-43
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"title": "Sample Test Case 2",
4+
"input": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
5+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
6+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
7+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
8+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
9+
"r": 1,
10+
"expected": 161700
11+
}
12+
]

src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_bruteforce.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
import { logger as console } from '../../../logger.js';
66

7-
export function countTriplets(arr, ratio) {
7+
function countTriplets(arr, ratio) {
88
const size = arr.length;
99
let counter = 0;
1010

@@ -24,3 +24,4 @@ export function countTriplets(arr, ratio) {
2424
}
2525

2626
export default { countTriplets };
27+
export { countTriplets };

src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_bruteforce.test.js

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,7 @@ import { logger as console } from '../../../logger.js';
33

44
import { countTriplets } from './count_triplets_1_bruteforce.js';
55

6-
const SMALL_TEST_CASES = [
7-
{
8-
title: 'Sample Test Case 0',
9-
input: [1, 2, 2, 4],
10-
r: 2,
11-
expected: 2
12-
},
13-
{
14-
title: 'Sample Test Case 1',
15-
input: [1, 3, 9, 9, 27, 81],
16-
r: 3,
17-
expected: 6
18-
},
19-
{
20-
title: 'Sample Test Case 1 (unsorted)',
21-
input: [9, 3, 1, 81, 9, 27],
22-
r: 3,
23-
expected: 1
24-
},
25-
{
26-
title: 'Sample Test Case 12',
27-
input: [1, 5, 5, 25, 125],
28-
r: 5,
29-
expected: 4
30-
}
31-
];
6+
import SMALL_TEST_CASES from './count_triplets_1.small.testcases.json';
327

338
describe('count_triplets_1', () => {
349
it('countTriplets test cases', () => {

src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_optimized.test.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,8 @@ import { describe, expect, it } from '@jest/globals';
22
import { logger as console } from '../../../logger.js';
33

44
import { countTriplets } from './count_triplets_1_optmized.js';
5-
import SMALL_TEST_CASES from './count_triplets_1_testcases.json';
6-
7-
const BIG_TEST_CASES = [
8-
{
9-
title: 'Sample Test Case 2',
10-
input: [
11-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
12-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
13-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
14-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
15-
],
16-
r: 1,
17-
expected: 161700
18-
}
19-
];
5+
import SMALL_TEST_CASES from './count_triplets_1.small.testcases.json';
6+
import BIG_TEST_CASES from './count_triplets_1.big.testcases.json';
207

218
describe('count_triplets_1 (optimized)', () => {
229
it('countTriplets small test cases', () => {

src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_optmized.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @see Solution Notes: [[docs/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1-solution-notes.md]]
44
*/
55

6-
export function countTriplets(arr, ratio) {
6+
function countTriplets(arr, ratio) {
77
let triplets = 0;
88

99
const aCounter = arr.reduce((accumulator, entry) => {
@@ -36,3 +36,4 @@ export function countTriplets(arr, ratio) {
3636
}
3737

3838
export default { countTriplets };
39+
export { countTriplets };

0 commit comments

Comments
 (0)