Skip to content

Commit ae5892a

Browse files
authored
Merge pull request #486 from sir-gon/develop
Develop
2 parents 619e424 + 48c29e3 commit ae5892a

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

src/hackerrank/interview_preparation_kit/arrays/new_year_chaos.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function minimumBribes(q) {
2929

3030
export function minimumBribesTransform(queue) {
3131
try {
32-
return minimumBribes(queue);
32+
return minimumBribes(queue).toString(10);
3333
} catch (e) {
3434
return TOO_CHAOTIC_ERROR;
3535
}

src/hackerrank/interview_preparation_kit/arrays/new_year_chaos.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { logger as console } from '../../../logger.js';
44
import { minimumBribesTransform, TOO_CHAOTIC_ERROR } from './new_year_chaos.js';
55

66
const TEST_CASES = [
7-
{ title: 'Test Case 0-0', input: [2, 1, 5, 3, 4], expected: 3 },
7+
{ title: 'Test Case 0-0', input: [2, 1, 5, 3, 4], expected: '3' },
88
{
99
title: 'Test Case 0-1',
1010
input: [2, 5, 1, 3, 4],
@@ -15,8 +15,8 @@ const TEST_CASES = [
1515
input: [5, 1, 2, 3, 7, 8, 6, 4],
1616
expected: TOO_CHAOTIC_ERROR
1717
},
18-
{ title: 'Test Case 1-2', input: [1, 2, 5, 3, 7, 8, 6, 4], expected: 7 },
19-
{ title: 'Test Case 2', input: [1, 2, 5, 3, 4, 7, 8, 6], expected: 4 }
18+
{ title: 'Test Case 1-2', input: [1, 2, 5, 3, 7, 8, 6, 4], expected: '7' },
19+
{ title: 'Test Case 2', input: [1, 2, 5, 3, 4, 7, 8, 6], expected: '4' }
2020
];
2121

2222
describe('new_year_chaos', () => {

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,27 @@ class Contest {
2929
this.luck = luck;
3030
this.important = important;
3131
}
32+
33+
getLuck() {
34+
return this.luck;
35+
}
36+
37+
isImportant() {
38+
return this.important !== 0;
39+
}
3240
}
3341

3442
export function luckBalance(k, contests) {
35-
// Write your code here
3643
let importantContests = [];
3744
const nonimportantContests = [];
3845

39-
contests.forEach((contest) => {
40-
const [luck, important] = [...contest];
41-
if (important === 1) {
42-
importantContests.push(new Contest(luck, important));
46+
contests.forEach((contestData) => {
47+
const [luck, important] = [...contestData];
48+
const contest = new Contest(luck, important);
49+
if (contest.isImportant()) {
50+
importantContests.push(contest);
4351
} else {
44-
nonimportantContests.push(new Contest(luck, important));
52+
nonimportantContests.push(contest);
4553
}
4654
});
4755

@@ -55,11 +63,11 @@ export function luckBalance(k, contests) {
5563
const cut = Math.min(k, size);
5664

5765
for (let i = 0; i < cut; i++) {
58-
total += importantContests[i].luck;
66+
total += importantContests[i].getLuck();
5967
}
6068

6169
for (let i = cut; i < size; i++) {
62-
total -= importantContests[i].luck;
70+
total -= importantContests[i].getLuck();
6371
}
6472

6573
nonimportantContests.forEach((contest) => {

0 commit comments

Comments
 (0)