0+ Learners

ONE STOP Learning Platform For TECH Interviews

Learn DSA, System Design, and Core CS Subjects with personalised roadmaps, expert videos, and practice built for results.

Curated sheets designed for a better learning experience.

Detailed videos and editorials to help you master every problem.

Stay consistent with streaks and leaderboard competition.

AI-powered instant doubt support for faster learning.

Strivers A2Z DSA Sheet

Run
1// Traverse the array once and maintain a running total by adding each element,2// ensuring an efficient and straightforward way to compute the final sum.3 4public class Main {5    public static void main(String[] args) {6        int[] arr = {1, 2, 3, 4, 5};7 8        int sum = 0;9        for (int num : arr) {10            sum += num;11        }12 13        System.out.println(sum); // Output: 1514    }15}
Problem

The Number of Ways to Make the Sum

Medium

Companies

Hints

Given an array arr of size n, your task is to efficiently compute the total sum of all elements in the array by iterating through each value.

Example 1

Input: n= 5, arr = [1, 2, 3, 4, 5]
Output: 15
Explanation: Sum of all elements is 1+2+3+4+5 = 15

Example 2

Input: n= 5, arr = [1, 2, 3, 4, 5]
Output: 15
Explanation: Sum of all elements is 1+2+3+4+5 = 15

Now your turn

Validate
Input: n= 3, arr = [13, 1, 1]
Output:
1
2
3
4

Constraints:

1 ≤ n ≤ 105

Hints:

Hint 1

Hint 1

Frequently Asked Questions:

Question 1

Question 2

Company

Interview Followup Questions:

Question 1

Question 2