Skip to content

Commit c6d9c7f

Browse files
committed
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Greedy Algorithms: Luck Balance.
* TEST data moved to JSON. * Adjusted the interface to match what hackerrank expects.
1 parent 0c193bc commit c6d9c7f

File tree

3 files changed

+46
-45
lines changed

3 files changed

+46
-45
lines changed

src/hackerrank/interview_preparation_kit/greedy_algorithms/luck-balance.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Contest {
3939
}
4040
}
4141

42-
export function luckBalance(k, contests) {
42+
function luckBalance(k, contests) {
4343
let importantContests = [];
4444
const nonimportantContests = [];
4545

src/hackerrank/interview_preparation_kit/greedy_algorithms/luck-balance.test.js

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,16 @@
11
import { describe, expect, it } from '@jest/globals';
22
import { logger as console } from '../../../logger.js';
33

4-
import { luckBalance } from './luck-balance.js';
4+
import luckBalance from './luck-balance.js';
55

6-
const TEST_CASES = [
7-
{
8-
'title': 'Sample Test case 0',
9-
'k': 3,
10-
'contests': [
11-
[5, 1],
12-
[2, 1],
13-
[1, 1],
14-
[8, 1],
15-
[10, 0],
16-
[5, 0]
17-
],
18-
'expected': 29
19-
},
20-
{
21-
'title': 'Sample Test case 1',
22-
'k': 5,
23-
'contests': [
24-
[13, 1],
25-
[10, 1],
26-
[9, 1],
27-
[8, 1],
28-
[13, 1],
29-
[12, 1],
30-
[18, 1],
31-
[13, 1]
32-
],
33-
'expected': 42
34-
},
35-
{
36-
'title': 'Sample Test case 1',
37-
'k': 2,
38-
'contests': [
39-
[5, 1],
40-
[4, 0],
41-
[6, 1],
42-
[2, 1],
43-
[8, 0]
44-
],
45-
'expected': 21
46-
}
47-
];
6+
import TEST_CASES from './luck-balance.testcases.json';
487

498
describe('luck-balance', () => {
509
it('luckBalance test cases', () => {
5110
expect.assertions(3);
5211

5312
TEST_CASES.forEach((test) => {
54-
const answer = luckBalance(test.k, test.contests);
13+
const answer = luckBalance.luckBalance(test.k, test.contests);
5514

5615
console.debug(
5716
`luckBalance(${test.k}, ${test.contests}) solution found: ${answer}`
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[
2+
{
3+
"title": "Sample Test case 0",
4+
"k": 3,
5+
"contests": [
6+
[5, 1],
7+
[2, 1],
8+
[1, 1],
9+
[8, 1],
10+
[10, 0],
11+
[5, 0]
12+
],
13+
"expected": 29
14+
},
15+
{
16+
"title": "Sample Test case 1",
17+
"k": 5,
18+
"contests": [
19+
[13, 1],
20+
[10, 1],
21+
[9, 1],
22+
[8, 1],
23+
[13, 1],
24+
[12, 1],
25+
[18, 1],
26+
[13, 1]
27+
],
28+
"expected": 42
29+
},
30+
{
31+
"title": "Sample Test case 1",
32+
"k": 2,
33+
"contests": [
34+
[5, 1],
35+
[4, 0],
36+
[6, 1],
37+
[2, 1],
38+
[8, 0]
39+
],
40+
"expected": 21
41+
}
42+
]

0 commit comments

Comments
 (0)