Insert into a Sorted Circular List
Updated
Problem statement
values records one complete traversal of a sorted circular singly linked list, beginning at its supplied head. A sorted circle has at most one strict decrease when comparing every entry with its circular successor. The head need not be the smallest value.
Insert value while keeping the old head. Scan edges from the head and choose the first edge a→b where either a≤b and a≤value≤b, or a>b and (value≥a or value≤b). If no edge qualifies, all old values are equal and different from the inserted value; insert just before the head.
Return one complete circle traversal from the original head after insertion. Empty input creates a one-node circle and returns [value].
Function
insertCircular(values: int[], value: int) → int[]Examples
Example 1
values = [3,4,1,2]value = 0return = [3,4,0,1,2]The first valid edge is the wrap edge 4→1. The old head value 3 remains first.
Example 2
values = [2,2,2]value = 1return = [2,2,2,1]No equal-valued old edge contains 1, so insertion falls back to the edge just before the head.
Constraints
0 <= values.length <= 2000.-1000000000 <= values[i], value <= 1000000000.- The original values have at most one strict descent over all circular successor pairs.
More Expedia Online Assessment questions
- Balanced NumbersOA · Seen Aug 2026
- REST API: Discounted PriceOA · Seen Aug 2026
- Maximum Team SizeOA · Seen Mar 2026
- Per-Domain Request LimiterOA · Seen Oct 2025
- Count Equal-Frequency SubsequencesOA · Seen Mar 2025
- Count Increasing Stock PeriodsOA · Seen Mar 2025
- Get Minimum StepsOA · Seen Oct 2024
- Rank Songs by PopularityOA · Seen Oct 2024
- Calculate the SumOA · Seen Oct 2024
- Get Maximum EfficiencyOA · Seen Oct 2024
Similar questions at other companies
- Minimize Task Resource ConsumptionNVIDIA · OANVIDIA interview questions
- Largest Microorganism After ConsumptionOpenAI · OAOpenAI interview questions
- Buffet Day GainsUpstart · OAUpstart interview questions
- Deep Copy a Random-Pointer ListAmazon · ONSITE INTERVIEW
- Merge One List Between Two PositionsOracle · ONSITE INTERVIEWOracle interview questions
- Insert into an Unrolled Linked ListIndeed · PHONE SCREEN · ONSITE INTERVIEWIndeed interview questions
- Insert into a Sorted Circular ListMeta · ONSITE INTERVIEWMeta interview questions
- Unique Target-Sum Pairs in a Sorted Doubly Linked ListArista Networks · PHONE SCREENArista Networks interview questions
- Deep Copy a Random-Pointer ListBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Pack Stream Chunks into Fixed-Capacity NodesBroadcom Limited · ONSITE INTERVIEW
Interview reports that mention this question
Expedia interview experiences
- Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
- Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
- Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
- Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
- Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)