Asked in today OA

Revision en1, by Jashwanth27, 2024-05-12 09:38:49

A family is about to break their piggy bank to use the money for different purposes. The piggy bank here represents an array (arr[]) consisting of N coins. The family has to split the coins of piggy bank into smaller stack (sub-array) of coins such that the sum of the difference between the maximum value and the minimum value of the coins for all the stacks (sub-arrays) is maximum. Note: Each value of the array can be used only once that is only in one subarray.

5 8 1 7 9 2

Ans = 14 -> (8-1) + (9-2) [8,1] max — 8, min = 1 [7 9 2] max = 9 min = 2

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Jashwanth27 2024-05-12 09:38:49 597 Initial revision (published)