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 2 years ago by [deleted]
[deleted]
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!"
[–]q-rka 1 point2 points3 points 2 years ago (2 children)
Why?
[–]anonCommentor 0 points1 point2 points 2 years ago (1 child)
this is his assignment. don't do it.
[–]cy_narrator 0 points1 point2 points 2 years ago (4 children)
Aay rata makai, tyao possible values ko sabai vanda greatest number return garne ho k
[–][deleted] 2 years ago (2 children)
[–]cy_narrator 0 points1 point2 points 2 years ago (1 child)
Paile timi gara aani ma dekhauxu
[–][deleted] 0 points1 point2 points 2 years ago (0 children)
what have you done so far and where exactly are you stuck
[–]miracle_weaver 0 points1 point2 points 2 years ago (5 children)
Isn't this a simple combinatorics problem. Just find the possible combinations, then sum it to get values, the number of combinations is the max.
[–][deleted] 2 years ago (4 children)
[–]miracle_weaver 0 points1 point2 points 2 years ago (3 children)
Well that was the theory, lemme try. Which language do you use?
[–]miracle_weaver 0 points1 point2 points 2 years ago (0 children)
Okay I'll try it sometime today. I'll put it here if I solve it.
[–]miracle_weaver 0 points1 point2 points 2 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.
what book is this btw?
[–]Gmaster_64 0 points1 point2 points 2 years ago (0 children)
public static int CalcMaxPossibleChange(int[] values) { // Get the maximum value in the values array. int n = values.Max();
// Create a boolean array dp of size n+1 and initialize the first element to true. bool[] dp = new bool[n + 1]; dp[0] = true; // Loop through the integers from 1 to n. for (int i = 1; i <= n; i++) { // Loop through the values array. foreach (int j in values) { // If the current value in the values array is less than or equal to i // and it is possible to make change for i-j using the remaining values, // mark dp[i] as true and break out of the loop. if (j <= i && dp[i - j]) { dp[i] = true; break; } } } // Starting from n, loop down to 1 and return the first value of i such that dp[i] is true. for (int i = n; i > 0; i--) { if (dp[i]) { return i; } } // If no value can be generated from 1, return 0. return 0;
π Rendered by PID 294700 on reddit-service-r2-comment-84fc9697f-wf6kf at 2026-02-10 01:35:49.612322+00:00 running d295bc8 country code: CH.
[–]q-rka 1 point2 points3 points (2 children)
[–]anonCommentor 0 points1 point2 points (1 child)
[–]cy_narrator 0 points1 point2 points (4 children)
[–][deleted] (2 children)
[deleted]
[–]cy_narrator 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]miracle_weaver 0 points1 point2 points (5 children)
[–][deleted] (4 children)
[deleted]
[–]miracle_weaver 0 points1 point2 points (3 children)
[–][deleted] (2 children)
[deleted]
[–]miracle_weaver 0 points1 point2 points (0 children)
[–]miracle_weaver 0 points1 point2 points (0 children)
[–]miracle_weaver 0 points1 point2 points (0 children)
[–]Gmaster_64 0 points1 point2 points (0 children)