Tweak
Code
Home
Roadmap
Courses
Problems
Dashboard
Pricing
FREE
Home
Roadmap
Courses
Problems
Dashboard
Pricing
Loading editor…
Python
Java
C++
JavaScript
TypeScript
C#
Go
Kotlin
Swift
Rust
Node 22.08.0
Reset
Run tests
Loading editor…
Test cases
Run to compare output
Case 1
Case 2
Input
prices = [7,1,5,3,6,4]
Expected
5
Output
—
Buy on day 1 (price = 1) and sell on day 4 (price = 6), profit = 6 - 1 = 5.