FastPrepFastPrep
Problem Brief

Get Largest Number

NEW GRADOA
See Amazon online assessment and hiring insights

The database specialists at Amazon are engaged in segmenting their sequence of interconnected servers. There exists a consecutive sequence of m servers, labeled from 1 to m, where the expense metric linked to the j-th server is given in the list expense[j]. These servers must be divided into precisely p separate server segments.

The expense of dividing a server segment from servers[x : y] is established as expense[x] + expense[y]. The aggregate expense accounts for the sum of partitioning costs for all server segments.

Given m servers, a list expense, and an integer p, determine both the least and greatest achievable total expense of these operations and return them as a list of length 2: [minimum expense, maximum expense].

Note: Splitting a list means dividing it into consecutive subsequences where each item belongs strictly to one segment. For a list [10, 20, 30, 40, 50], a valid segmentation would be [[10], [20, 30], [40, 50]], while [[10, 20], [20, 30], [40, 50]] and [[10, 30], [20, 40, 50]] would be deemed incorrect 😭.

1Example 1

Input
expense = [1, 2, 3, 2, 5], p = 3
Output
[14, 18]
Explanation
Example 1 illustration

2Example 2

Input
expense = [1, 2, 3, 4], p = 2
Output
[12, 8]
Explanation
Answer : Max = 12 [1+3,4+4] First Partition Is From Index 0 To 2 , second From 3 To 3 Min = 8 [1+1,2+4] First Partition From Index 0 to 0 , second From 1 To 3 PPS: This test case was added on 03-28-2025. Relevant source ss was included in the Problem Source section below.

Constraints

Limits and guarantees your solution can rely on.

πŸ‘‹πŸ˜ƒπŸ‘
public int[] getLargestNumber(int[] expense, int p) {
  // write your code here
}
Input

expense

[1, 2, 3, 2, 5]

p

3

Output

[14, 18]

Sign in to submit your solution.