FastPrepLongest-Waiting Unique Task
Problems/Longest-Waiting Unique Task

Longest-Waiting Unique Task

Amazon logoAmazon● EasyNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A first-hand Amazon new grad phone screen report gave an example of tasks in order and the goal of finding the task that has waited longest. It did not give a function signature, what to return for no result, what the IDs look like, or the limits. In our version, a waiting task is an ID that has been seen exactly once. It is about 90% the same as the reported question.

Special thanks: ദ്ദി˙∇˙)ว A special thank you to our lovely, amazing frenz for sharing interview updates and helping keep this question up to date!

The array tasks records task sightings in the order they happened. A task is still waiting only when its identifier appears exactly once in the whole array.

Among all waiting tasks, return the identifier whose only sighting comes first. That task has waited the longest. If no task is waiting, return the empty string.

Task identifiers are compared case-sensitively.

Sibling variants: same core, different skin

These four problems are sibling variants of the same first-unique pattern. Their stories and the timing of their queries differ. Each one still looks for the earliest value that has appeared exactly once.

  1. Longest-Waiting Unique Task (current)
  2. Dynamic Longest-Waiting Unique Task Queries
  3. First User to Log In Exactly Once
  4. First Unique Character in a Stream

Function

longestWaitingUniqueTask(tasks: String[]) → String

Examples

Example 1

tasks = ["A","B","C","D","A"]return = "B"

A appears twice, so it is not waiting. B, C, and D each appear once. B comes first among them, so the answer is "B".

Example 2

tasks = ["A","B","A","B"]return = ""

Both identifiers, A and B, appear twice, so no task is waiting. The answer is the empty string.

Example 3

tasks = ["build","deploy","test"]return = "build"

Every task appears once, so all of them are waiting. build was seen first, so it has waited the longest. The answer is "build".

Constraints

  • 1 <= tasks.length <= 100000.
  • Each task identifier is a nonempty alphanumeric string of length at most 40.
  • Task identifiers are case-sensitive.

More Amazon Phone Screen questions

  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Search in a Rotated Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent ElementsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
  • Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
  • Second Largest Distinct ElementPHONE SCREEN · Seen Nov 2026
  • Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Merchant Payout Reserve CalculatorStripe · PHONE SCREENStripe interview questions
  • Price CheckBlue Origin · PHONE SCREEN
  • Majority ElementByteDance · PHONE SCREENByteDance interview questions
  • Detect a Straight FlushTemu · PHONE SCREENTemu interview questions
  • Recommend Films from Viewers Who Watched Everything You DidBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Find Unique ElementsCisco · PHONE SCREENCisco interview questions
  • Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions
  • Employee Count Median, Mean and ModeClay · PHONE SCREEN
  • Two SumBNSF Railway · PHONE SCREENBNSF Railway interview questions
  • Single-Condition Product FilterCrowdstrike · PHONE SCREENCrowdstrike interview questions

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
  • Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)
See Amazon hiring insights
Saved
class Solution {
    public String longestWaitingUniqueTask(String[] tasks) {
        // write your code here
    }
}
Checking account…