Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function minimumBribes(q) {

export function minimumBribesTransform(queue) {
try {
return minimumBribes(queue);
return minimumBribes(queue).toString(10);
} catch (e) {
return TOO_CHAOTIC_ERROR;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { logger as console } from '../../../logger.js';
import { minimumBribesTransform, TOO_CHAOTIC_ERROR } from './new_year_chaos.js';

const TEST_CASES = [
{ title: 'Test Case 0-0', input: [2, 1, 5, 3, 4], expected: 3 },
{ title: 'Test Case 0-0', input: [2, 1, 5, 3, 4], expected: '3' },
{
title: 'Test Case 0-1',
input: [2, 5, 1, 3, 4],
Expand All @@ -15,8 +15,8 @@ const TEST_CASES = [
input: [5, 1, 2, 3, 7, 8, 6, 4],
expected: TOO_CHAOTIC_ERROR
},
{ title: 'Test Case 1-2', input: [1, 2, 5, 3, 7, 8, 6, 4], expected: 7 },
{ title: 'Test Case 2', input: [1, 2, 5, 3, 4, 7, 8, 6], expected: 4 }
{ title: 'Test Case 1-2', input: [1, 2, 5, 3, 7, 8, 6, 4], expected: '7' },
{ title: 'Test Case 2', input: [1, 2, 5, 3, 4, 7, 8, 6], expected: '4' }
];

describe('new_year_chaos', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,27 @@ class Contest {
this.luck = luck;
this.important = important;
}

getLuck() {
return this.luck;
}

isImportant() {
return this.important !== 0;
}
}

export function luckBalance(k, contests) {
// Write your code here
let importantContests = [];
const nonimportantContests = [];

contests.forEach((contest) => {
const [luck, important] = [...contest];
if (important === 1) {
importantContests.push(new Contest(luck, important));
contests.forEach((contestData) => {
const [luck, important] = [...contestData];
const contest = new Contest(luck, important);
if (contest.isImportant()) {
importantContests.push(contest);
} else {
nonimportantContests.push(new Contest(luck, important));
nonimportantContests.push(contest);
}
});

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

for (let i = 0; i < cut; i++) {
total += importantContests[i].luck;
total += importantContests[i].getLuck();
}

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

nonimportantContests.forEach((contest) => {
Expand Down