Stock Market Sherlock is a mad data scientist. Recently he drew a histogram using a dataset with size N from stock market showing the stock price on each day. Those days are consecutive. Can you help him find out the rectangle of the maximum area in the corresponding histogram? Example: Max Area = 3 x 4 = 12 4 1 2.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Please answer

Stock Market
Sherlock is a mad data scientist. Recently he drew a histogram using a
dataset with size N from stock market showing the stock price on each
day. Those days are consecutive. Can you help him find out the
rectangle of the maximum area in the corresponding histogram?
Example:
Max Area = 3 x 4 = 12
6.
4
2
Transcribed Image Text:Stock Market Sherlock is a mad data scientist. Recently he drew a histogram using a dataset with size N from stock market showing the stock price on each day. Those days are consecutive. Can you help him find out the rectangle of the maximum area in the corresponding histogram? Example: Max Area = 3 x 4 = 12 6. 4 2
Input
The first line of input is an integer T (1 <=T<= 10) representing the
number of test cases. Each test case will follow the format shown
below:
The first line: An integer N showing the number of days in the dataset.
The second line: N integers p1,p2,.pN showing stock prices on each
day.
(1 <= N<= 100000, 1 <= pi <= 100000).
Output
For each case, print a single line containing the maximum area of the
rectangle in the histogram.
Sample Input
Sample Output
12
2
12
345238
7
6254516
Explanation for the sample 2:
We will choose consecutive days with price (5 4 5} to get the max area 12 as in
the figure.
Tips: the result may be bigger than the range of int, you may consider using long
long int instead of int.
Transcribed Image Text:Input The first line of input is an integer T (1 <=T<= 10) representing the number of test cases. Each test case will follow the format shown below: The first line: An integer N showing the number of days in the dataset. The second line: N integers p1,p2,.pN showing stock prices on each day. (1 <= N<= 100000, 1 <= pi <= 100000). Output For each case, print a single line containing the maximum area of the rectangle in the histogram. Sample Input Sample Output 12 2 12 345238 7 6254516 Explanation for the sample 2: We will choose consecutive days with price (5 4 5} to get the max area 12 as in the figure. Tips: the result may be bigger than the range of int, you may consider using long long int instead of int.
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY