Compute max profit from one stock trade
Company: Flipster
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Technical Screen
Quick Answer: This question evaluates a candidate's understanding of array-based data processing, difference maximization, and basic algorithmic optimization for time-series inputs. It is commonly asked in Coding & Algorithms interviews to assess fundamental practical programming ability and attention to edge cases (e.g.
Constraints
- n >= 1 in normal inputs
Examples
Input: ([7, 1, 5, 3, 6, 4],)
Expected Output: 5
Input: ([7, 6, 4, 3, 1],)
Expected Output: 0
Input: ([1],)
Expected Output: 0
Hints
- Track the minimum price seen so far.