Highly Profitable Intervals

Company: Ibm_22sep

Difficulty: medium

Problem Statement

Highly Profitable Intervals Problem Description The stock performance of a company is being examined to assess its net profit over time. You are given the stock price of the company for each of n consecutive months, stockPrices[0], stockPrices[1], ..., stockPrices[n-1] , and an analysis parameter k . An interval of k consecutive months is highly profitable if the stock price increases strictly throughout those k months, that is, every month's price is strictly greater than the previous month's price inside the interval. Two equal prices in a row break the increase. Complete the function countHighlyProfitableIntervals(stockPrices, k) , which returns the number of highly profitable intervals of length exactly k . Input Format Read from standard input. n k stockPrices[0] stockPrices[1] ... stockPrices[n-1] The first line contains two integers n and k : the number of months and the interval length. The second line contains n integers, the stock prices in month order. (inferred -- the sourc