Back to problems

Solve stock profit and vertical tree traversal

Algorithm · Uber · Medium

You have 60 minutes to solve both algorithm tasks below. Task 1 — Maximum Profit from a Single Stock Trade You are given an integer array prices. Days are numbered from 0, and prices[i] is the trading price on day i. Choose exactly one purchase day and one sale day. The sale day must have a strictly larger index than the purchase day. Return the largest possible profit, defined as sale price minus purchase price, from one complete transaction. If no transaction can produce a…

Checking your access…