In securities research, an analyst will look ata number of attributes for a stock. Oneanalyst would like to keep a record of thehighest positive spread between a closingprice and the closing price on any prior dayin history. Determine the maximum positivespread for a stock given its price history. Ifthe stock remains flat or declines for the fullperiod, return -1.Example opx - 17. 1. 2. 5)Calculate the positive difference betweeneach price and its predecessors:* Ar the first quore, there is no earlierquote to compare to,. At the second quote, there was no earllerAt the third quote the price is ngre tuan
Answers
Answer:
12 ka 4 4 2 ka 8 8 2 ka 4 kkkkkkkkk
Insecurities research, an analyst will look data the number of attributes for a stock.
One analyst would like to keep a record of the highest positive spread between a closing price and the closing price on any prior day in history.
Explanation:
static int maxDifference(int[] a) {
//test array size
if (a.length < 1 || a.length > 1_000_000) return -1;
int[] oldArr = Arrays.copyOf(a, a.length);
Arrays.sort(a);
int max = a[a.length - 1];
if (max > 1_000_000 || a[0] < -1_000_000) return -1;
int min = max;
for (int i = 0; i < oldArr.length; i++) {
if (oldArr[i] < max) {
min = Math.min(min, oldArr[i]);
}
if (oldArr[i] == max) break;
}
int result = min == max ? -1 : max - min;
return result;
}