Skip to content

Commit 281be20

Browse files
sir-gonGonzalo Diaz
authored and
Gonzalo Diaz
committed
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Dynamic Programming: Max Array Sum. Adjusted the interface to match what hackerrank expects.
1 parent 90accbf commit 281be20

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/hackerrank/interview_preparation_kit/dynamic_programming/max_array_sum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
const bigIntMax = (...args) =>
77
args.reduce((m, e) => (e > m ? e : m), BigInt(0));
88

9-
export function maxSubsetSum(arr) {
9+
function maxSubsetSum(arr) {
1010
const arrCopy = arr.map((x) => BigInt(x));
1111

1212
if (arrCopy.length === 0) {

src/hackerrank/interview_preparation_kit/dynamic_programming/max_array_sum.test.js

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

4-
import { maxSubsetSum } from './max_array_sum.js';
4+
import maxArraySum from './max_array_sum.js';
55

66
import TEST_CASES from './max_array_sum.testcases.json';
77
import TEST_CASE3 from './max_array_sum.testcase3.json';
@@ -15,7 +15,9 @@ describe('max_array_sum', () => {
1515
expect.assertions(4);
1616

1717
ALL_TEST_CASES.forEach((test) => {
18-
const answer = maxSubsetSum(test.input).toString(DECIMAL_RADIX);
18+
const answer = maxArraySum
19+
.maxSubsetSum(test.input)
20+
.toString(DECIMAL_RADIX);
1921

2022
console.debug(`maxSubsetSum(${test.input}) solution found: ${answer}`);
2123

@@ -29,7 +31,7 @@ describe('max_array_sum', () => {
2931
const input = [];
3032
const expected = 0;
3133

32-
const answer = maxSubsetSum(input);
34+
const answer = maxArraySum.maxSubsetSum(input);
3335

3436
console.debug(`maxSubsetSum(${input}) solution found: ${answer}`);
3537

@@ -42,7 +44,7 @@ describe('max_array_sum', () => {
4244
const input = [1];
4345
const expected = 1;
4446

45-
const answer = maxSubsetSum(input);
47+
const answer = maxArraySum.maxSubsetSum(input);
4648

4749
console.debug(`maxSubsetSum(${input}) solution found: ${answer}`);
4850

0 commit comments

Comments
 (0)