Amazon Kindle has several e-books that customers can purchase directly.
There are n books ordered sequentially numbered 1, 2,.., n, where the ith book
has a cost of cost[i]. A customer wants to purchase all the books, and kindle offers the customer a unique
scheme is described as the follows -
i. The customer can choose to buy the leftmost book individually for cost[i]. This book is then removed from the sequence.j. The customer can choose to buy the rightmost book individually for cost[j]. This book is then removed from the sequence.Given the cost of books cost, the cost to purchase the leftmost and rightmost books together, parCost, and the mx num of times the pairCost option can be applied k, find the min cost in which the customer can purchase all the books following the scheme above.
Complete the function getMinCost in the editor.
getMinCost has the following parameters:
int cost[n]: the cost of each bookint pairCost: the cost of purchase the leftmost and rightmost book togetherint k: the MAX NUM of times pairCost can be used
Returns
long int: the min cost to purchase all books
Endless thanks to our best friend for their kind help in sharing the source!
cost = [1, 2, 3] pairCost = 2 k = 1 return = 3

cost = [1, 1, 1] pairCost = 2 k = 1 return = 3
cost = [9, 11, 13, 15, 17] pairCost = 6 k = 2 return = 21
1 <= n <= 10^51 ≤ pairCost ≤ 10^91 ≤ k ≤ n1 <= cost[i] <= 10^9The cost array may not be in increasing order- Minimum Operations to Make the Integer ZeroSeen Jun 2026
- Create Array Generator ServiceSeen Jun 2026
- Minimum Merge ConflictsOA · Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Drone Delivery RouteOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Minimum Operations to Make Array ValidOA · Seen Jun 2026
- Sort Bug Report FrequenciesOA · Seen Jun 2026
public long getMinCost(int[] cost, int pairCost, int k) {
// write your code here
}