Largest Subset Sum

Company: Mathworks

Difficulty: medium

Problem Statement

Largest Subset Sum You are given an array `arr` of `n` integers. For each number in the array: Find all of its positive factors (including `1` and the number itself). Compute the sum of those factors. Return an array where each element contains the sum of factors of the corresponding number in `arr`. Input Format The first line contains the integer `n`, the size of `arr[]`. The next `n` lines each contain one integer element of `arr[]`. Output Format Print `n` lines. The `i`-th line contains the sum of the positive factors of `arr[i]`, in the same order as the input. Constraints `1 <= n <= 10^3` `1 <= arr[i] <= 10^9` Each answer can be as large as roughly `4 * 10^9`, which does **not** fit in a signed 32-bit integer. Use a 64-bit integer type (`long long` in C++, `long` in Java). The values are printed one per line and are never summed together, so no larger accumulator is needed. Example 1 1 12 Output: 28 Explanation: the factors of `12` are `[1, 2, 3, 4, 6, 12]`. Their su