← Ramp Interview Insights

Ramp·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Ramp coding screen for a software engineer role. One algorithmic problem, stock trading themed, which sounds like a classic leetcode variant but has a small twist with the unsorted multi-stock input format that can trip you up if you're not careful.

Questions Asked (1)

Q1

Given a list of unsorted trading records (date, stock ticker, price) for multiple stocks, compute the maximum total profit you can make across all stocks. You can make unlimited transactions per stock, hold multiple stocks simultaneously, but can only hold one unit of any single stock at a time and must start and end with no holdings.

Algorithms & Data Structures
Author's notes

The core insight is the same as the classic 'best time to buy and sell stock with unlimited transactions' problem: just sum up every positive day-over-day price increase.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Recognize that since stocks are independent and you can hold multiple simultaneously, the maximum total profit is the sum of maximum profits for each stock individually. For each stock, sort its records by date, then apply the standard 'best time to buy and sell stock II' greedy algorithm: sum all positive price differences between consecutive days. This yields O(N log N) time due to sorting, or O(N) if records are already grouped and sorted per stock.

Pro tip: Clarify upfront that the 'one unit per stock' constraint means each stock's transactions are independent, so you can solve per stock and sum. Also mention that if the input is already sorted by date, you can avoid the sort and achieve O(N) time.

1. Clarify constraints and assumptions

Confirm that transactions across different stocks are independent, that you can hold multiple stocks at once, and that you must end with no holdings. Ask if the input is sorted by date or if you need to sort it.

2. Group records by stock ticker

Use a hash map to group all records by ticker, so you can process each stock's price series independently.

3. Sort each stock's records by date

For each stock, sort its records chronologically. If the input is already sorted, this step can be skipped.

4. Compute max profit per stock using greedy sum of positive differences

Iterate through the sorted prices and add the positive difference between each consecutive pair. This captures all profitable upswings.

5. Sum profits across all stocks and return total

Accumulate the per-stock profits to get the maximum total profit, ensuring you start and end with no holdings.

Key Points to Mention

  • Independence of stocks: since you can hold multiple stocks simultaneously, the total profit is the sum of individual stock profits.
  • Greedy algorithm for unlimited transactions: sum all positive price changes between consecutive days.
  • Time complexity: O(N log N) due to sorting, or O(N) if input is already sorted by date per stock.
  • Space complexity: O(N) for grouping and sorting, or O(1) extra if processing in place.
  • Edge cases: empty input, single record, decreasing prices (profit 0), duplicate dates.
  • Proof of optimality: any profitable transaction can be decomposed into consecutive day trades, so summing positive differences is optimal.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.