FastPrepSubmask Sum Queries
Problems/Submask Sum Queries

Submask Sum Queries

Intuit logoIntuit● HardINTERNOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source screenshot begins within the examples and omits numerical limits. The judged core task matches the report at about 94%.

You are given a nonnegative bit count n, an integer array values of length 2^n, and an array of query masks queries.

A mask s is a submask of m when every set bit of s is also set in m. For each query mask m, return the sum of values[s] over every submask s of m. Return answers in the same order as the queries.

Function

sumSubmaskValues(n: int, values: long[], queries: int[]) → long[]

Examples

Example 1

n = 2values = [1,2,3,4]queries = [3,1]return = [10,3]

Every mask from 0 through 3 is a submask of 3, so the first sum is 1 + 2 + 3 + 4 = 10. The submasks of 1 are 0 and 1, producing 1 + 2 = 3.

Example 2

n = 1values = [-2,5]queries = [0,1]return = [-2,3]

Mask 0 has only itself as a submask, so the first result is -2. Mask 1 has submasks 0 and 1, producing -2 + 5 = 3.

Constraints

  • 0 ≤ n ≤ 12 and values.length = 2^n.
  • -10^9 ≤ values[i] ≤ 10^9.
  • 1 ≤ queries.length ≤ 1000 and every query is a valid mask in [0, 2^n - 1].
  • Every answer fits in a signed 64-bit integer.

More Intuit problems

  • VIP and Regular Service SchedulerPHONE SCREEN · Seen Nov 2026
  • Employee Promotion OpportunitiesOA · Seen Oct 2026
  • Next Pascal Row CoefficientOA · Seen Oct 2026
All Intuit interview questionsSee Intuit hiring insights
Saved
class Solution {
    public long[] sumSubmaskValues(int n, long[] values, int[] queries) {
      // Write your code here.
    }

}
Checking account…