FastPrepSecond Largest Distinct Element
Problems/Second Largest Distinct Element

Second Largest Distinct Element

Amazon logoAmazon● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionExamples

Problem statement

Source note: Reported in an Amazon (AWS) SDE II phone screen. The second of its two coding questions asked for the runner-up value of a list in which some numbers can appear more than once.

The report gives no examples or limits and does not say what to return when no runner-up exists. Here, the answer is the second largest distinct value, -1 means there is none, and values are never negative, so -1 cannot be a real answer. Arrays have up to 10^5 elements.

Our version is about 85% the same as the reported question.

You are given an integer array nums that may contain repeated values.

Return the second largest distinct value in nums: the largest value that is strictly smaller than the maximum of nums. Copies of the maximum do not count as a second largest.

The problem statement continues
Pro

Examples

Example 1

nums = [12,35,1,10,34,1]return = 34
  • The largest value is 35.
  • The largest value smaller than 35 is 34, so the answer is 34.
02 · Example 2
FastPrep Pro
Reported in 1 Amazon interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week

More Amazon Phone Screen questions

  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE 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
  • Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent ElementsOA · PHONE SCREEN · Seen Nov 2026
  • Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 3SumPHONE SCREEN · Seen Nov 2026

Similar questions at other companies

  • Best Time to Buy and Sell StockMeta · PHONE SCREENMeta interview questions
  • Lazy Filter over a GeneratorSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
  • Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
  • Best Stock Trade with Buy and Sell DaysGoogle · PHONE SCREENGoogle interview questions
  • Search and Format ContactsAdyen · PHONE SCREENAdyen interview questions
  • 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
  • Total Years of Work ExperienceLinkedIn · PHONE SCREENLinkedIn interview questions
  • Array-Backed Set Without Library CollectionsOde with Anthropic · PHONE SCREEN

Interview reports that mention this question

  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 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
CodePython 3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import heapq
from collections import defaultdict
 
class Solution:
def solve(self, values, queries):
# Build the adjacency structure
n = len(values)
graph = defaultdict(list)
for u, v in queries:
graph[u].append(v)
 
best = [float("inf")] * n
heap = [(0, 0)]
while heap:
cost, node = heapq.heappop(heap)
if cost > best[node]:
continue
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Amazon interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week