Form Largest Integer With Digits That Add up to Target LeetCode solution in JavaScript

1
var largestNumber = function (cost, target) {
2
const arr = new Array(target + 1).fill("#");
3
arr[0] = "";
4

5
for (let i = 0; i < 9; i++) {
6
for (let j = cost[i]; j <= target; j++) {
7
if (
8
arr[j - cost[i]] !== "#" &&
9
arr[j - cost[i]].length + 1 >= arr[j].length
10
) {
11
arr[j] = (i + 1).toString().concat(arr[j - cost[i]]);
12
}
13
}
14
}
15

16
return arr[target] == "#" ? "0" : arr[target];
17
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0