BackmediumArrays Salesforce

Galactic Treasure Hunt Solution

Problem Statement

Given an array of integers representing the number of gems in each chest on each planet, find the maximum sum of gems that can be collected by visiting a subsequence of planets.

Example 1
Input
[3, 7, 1]
Output
11

Explanation: Step-by-step: We start with the array [3, 7, 1]. We can include all numbers to get the maximum sum: 3 + 7 + 1 = 11.

Example 2
Input
[10, 30, 40, 50]
Output
130

Explanation: Step-by-step: We start with the array [10, 30, 40, 50]. We can include all numbers to get the maximum sum: 10 + 30 + 40 + 50 = 130.

Constraints

  • 1 <= arr.length <= 10^5
  • -10^5 <= arr[i] <= 10^5
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free