Stock Price Analyzer

Easy
array greedy dynamic-programming
Problem Description

Given daily stock prices, find the maximum profit from buying and selling once. You must buy before you sell.

Input Format
First line contains n (number of days). Second line contains n prices.
Output Format
Maximum profit possible, or 0 if no profit can be made
Constraints
1 ≤ n ≤ 10^5, 1 ≤ prices ≤ 10^4
Sample Input/Output
Input:
6
7 1 5 3 6 4
Output:
5
Explanation

Buy at price 1 and sell at price 6 for profit of 5

Solution Hints
  • Read carefully: Understand input/output format and constraints
  • Start simple: Think of brute force solution first, then optimize
  • Edge cases: Consider empty inputs, single elements, max constraints
  • Data structures: Choose arrays, hash maps, sets based on problem needs
  • Time complexity: Ensure your solution fits within time limits
  • Test examples: Verify logic with provided sample inputs
130
Points
2000ms
Time Limit
256MB
Memory Limit
Code Editor
Register to Submit
Register to Access Code Editor

Create a free account to solve coding problems and track your progress.

Register Now
Feedback