Tensara Logo

tensara

All Problems

Cumulative Sum

MEDIUM

Compute the cumulative sum (also known as prefix sum or scan) of an input array:

output[i]=j=0iinput[j]\text{output}[i] = \sum_{j=0}^{i} \text{input}[j]

The cumulative sum at each position is the sum of all elements up to and including that position.

Input:

  • Vector input\text{input} of size N\text{N}

Output:

  • Vector output\text{output} of size N\text{N} containing cumulative sums

Notes:

  • The first element of the output is equal to the first element of the input
  • This problem is adapted from KernelBench
Console

Sample Run Results

Hit "Run" to test your code with sample inputs

Loading...

Loading editor...

CUDA C++ environment

Desktop Required for Code Submission

For the best coding experience, please switch to a desktop device to write and submit your solution.