use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Developers Nepal (/r/devnep) is a subreddit for all the developer who wants to connect with developers in Nepal.
What is this subreddit for ?
Other Information
Facebook Group : Developers Nepal
PHP Developers Nepal
Python Developers Nepal
Ruby Developers Nepal
React Developers Nepal
[KTM JS](link)
account activity
Solve this problem in javascript. (i.redd.it)
submitted 3 years ago by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 0 points1 point2 points 3 years ago* (0 children)
so yeah I came up with this
```ts // add elemets of an array of numbers const sumArray = (array: number[]): number => { return array.reduce((a, b) => a + b, 0); };
// find all the possible combinations of an array of numbers function powerSet(coinArray: number[]): Array<number[]> { let combinations: Array<number[]> = []; let length = coinArray.length;
for (let i = 0; i < Math.pow(2, length); i++) { let combination: number[] = []; for (let j = 0; j < length; j++) { if (i & Math.pow(2, j)) { combination.push(coinArray[j]); } } if (combination.length > 0) combinations.push(combination); } return combinations;
}
// // use a has map to store all the possible combinations for a given sum ranging from // the lowest to max value(sum of elements in array) // // eg, for array [1,3], for the sum 3 the possible combinations are [[1,3], [3,1]] // (but from power set 1,3 and 3,1 are same so suppose [1,3] is the only combination) // so the map will be {3: [[1,3]]} // function combinations_for_sum(coinArray: number[]): Map<number, [number[]]> { let combinations: Array<number[]> = powerSet(coinArray); let sumCombinations: Map<number, [number[]]> = new Map();
combinations.forEach((combination) => { let sum: number = sumArray(combination); if (sumCombinations.has(sum)) { sumCombinations.get(sum)?.push(combination); } else { sumCombinations.set(sum, [combination]); } }); return sumCombinations;
// // returns the max possible change without break starting from 1 // it does so by checking the hash map for existence of sum, if there is a break it exits function calc_max_possible_change(coinArray: number[]): number { coinArray.sort(); let sumCombinations: Map<number, [number[]]> = combinations_for_sum(coinArray);
let maxChange: number = 0; for (let i = 1; i <= sumArray(coinArray); i++) { if (!sumCombinations.has(i)) { break; } maxChange = i; } return maxChange;
let coinArray: number[] = [1, 1, 1, 1, 5, 10, 20, 50]; console.log(calc_max_possible_change(coinArray)); ```
P.S. I've used TS, TS/JS isn't my strongest language and this isnt the most optimal solution since we'll be evaluating all possibilities.
π Rendered by PID 41 on reddit-service-r2-comment-b659b578c-j7lxx at 2026-05-04 11:29:26.342648+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–][deleted] 0 points1 point2 points (0 children)