BackmediumArrays Accenture

Galactic Expedition Routes Solution

Problem Statement

Given an array of distances between space stations and a target fuel capacity, find all distinct subarrays of various lengths that sum up to the target fuel capacity, excluding empty subarrays.

Example 1
Input
[10, 20, 30, 40]
Output
[[10, 20, 30], [20, 30, 30]]

Explanation: Step-by-step: Given the array [10, 20, 30, 40] and target fuel capacity 50, we first find all possible subarrays. Then, we filter out the subarrays that sum up to the target fuel capacity. Finally, we exclude empty subarrays from the result.

Example 2
Input
[15, 35, 45]
Output
[[15, 35]]

Explanation: Step-by-step: Given the array [15, 35, 45] and target fuel capacity 50, we first find all possible subarrays. Then, we filter out the subarrays that sum up to the target fuel capacity. Finally, we exclude empty subarrays from the result.

Constraints

  • 1 <= array length <= 1000
  • 1 <= distance values <= 10000
  • 1 <= target fuel capacity <= 100000
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