Company: Amazon_24oct
Difficulty: medium
Total Distinct Differences Problem Description Some engineers at Amazon are developing analytical tools to process data sequences from their monitoring systems. One such tool analyzes an array of integers. It randomly selects any subsequence of size greater than 2 and returns the difference between the highest and the second-highest elements of that subsequence. To evaluate this algorithm, given an array of n integers, find the sum of all possible distinct values that can be generated using this tool. Given an array values of n integers, find the sum of different possible numbers that can be obtained by the difference of the highest and the second-highest elements of any subsequence of the given array. Here, a subsequence of array A is defined as 2 or more contiguous elements A i , A i+1 , ..., A j such that 1 ≤ i < j ≤ n. Note: The second highest element of the array may be equal to the highest element of the array. Examples Example 1: Here n = 3 and values = [6, 2, 4] . Subs