BETA Can't read the text? Switch theme 3. Largest Subset Sum For each number in an array, get the sum of its factors. Re
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
BETA Can't read the text? Switch theme 3. Largest Subset Sum For each number in an array, get the sum of its factors. Re
M Returns long[n]: the sums calculated for each arr Constraints • 1≤n<10³ • 1 ≤ arr ≤ 10⁹ Input Format For Custom Testing Input from stdin will be processed as follows and passed to the function. The first line contains an integer n, the number of elements in arr. Each of the next n lines contains an integer describing arr. Sample Case 0 Sample Input 0 STDIN Function 2 arr [] size n = 2 arr = [2, 4] 2 Sample Output 0
Input from stdin will be processed as follows and passed to the function. The first line contains an integer n, the number of elements in arr. Each of the next n lines contains an integer describing arr. Sample Case 0 Sample Input 0 STDIN Function 2 arr[] size n = 2 2 arr = [2, 4] Sample Output 0 Explanation 0 Factors of arr[0] = 2 are [1, 2] and their sum is 3. Factors of arr[1] = 4 are [1, 2, 4] and their sum is 7. 37
er Info с & Autocomplete Ready Ⓒ 1> #include <assert.h>... 19 20 /* 21 * Complete the 'maxSubsetSum' function below. 22 23 * The function is expected to return a LONG_INTEGER_ARRAY. 24 * The function accepts INTEGER ARRAY k as parameter. 25 */ 26 27 28 * To return the long integer array from the function, you should: 29 Store the size of the array to be returned in the result_count variable - Allocate the array statically or dynamically 30 31 32 * For example, 33 * long* return_long_integer_array_using_static_allocation (int* result_count) { *result_count = 5; 34 ★ 35 ✰ 36 static long a[5] = {1, 2, 3, 4, 5); 37 38 ✰ return a; 39 40 41 * long* return_long_integer_array_using_dynamic_allocation (int* result_count) { *result_count = 5; 42 43 www *** Line: 55 Col: 5
33 Long* return_long_integer_array_using_static_allocation (int* result_count) { 34 ★ *result_count = 5; 35 36 static long a[5] = {1, 2, 3, 4, 5); 37 38 ★ return a; 39 * } 40 41 * long* return_long_integer_array_using_dynamic_allocation (int* result_count) { 42 ★ *result_count = 5; 43 44 long a = malloc (5+ sizeof(long)); 45 46 for (int i = 0; i < 5; i++) { 47 *(a + i) = i + 1; 48 } 50 return a; 51 52 ★ 53 54 Long* maxSubsetSum(int k_count, int* k, int* result_count) 55 56 57 58> int main() 49 ★ Line: 55 Col: