Maximum Tips From Delivery Slots Without Taking Adjacent Ones

Last updated: November 29, 2026

Quick Overview

A courier is offered a sequence of back-to-back delivery slots with expected tips; taking a slot makes the next one impossible because of travel time. Return the maximum total tips the courier can collect.

Uber
Coding & Algorithms
Software Engineer
Uber
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


A courier is offered a sequence of back-to-back delivery slots with expected tips; taking a slot makes the next one impossible because of travel time. Return the maximum total tips the courier can collect.

A light Uber Eats framed DP warm-up used in phone screens to see whether you can define a state and recurrence cleanly before moving to something harder. The interviewer checks the take-or-skip recurrence and the O(1) space version.

What the Interviewer Expects
  • Define the take or skip recurrence
  • Handle empty and single-slot inputs
  • Reduce space to two variables
  • Explain why greedy by largest tip fails
  • Mention how to recover the chosen slots
Key Topics to Cover
dynamic programming
1D DP
space optimization
take or skip
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • What if the slots form a loop (the first and last are adjacent)?
  • What if taking a slot blocks the next two slots?
  • Return the chosen slot indices
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: list of non-negative tips t, one per slot in time order.
  • Cannot take two consecutive slots, because the courier cannot finish one drop-off and reach the next pickup in time.
  • Output: max...
High-Level Design

Let best[i] be the maximum using slots 0..i. Either skip slot i (best[i - 1]) or take it (best[i - 2] + t[i]). Only the previous two values are needed, so two variables suffice. Greedy by la...


Submit Your Answer
Markdown supported