FastPrepInsert into a Sorted Circular List
Problems/Insert into a Sorted Circular List

Insert into a Sorted Circular List

Meta logoMeta● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Meta onsite interview. The original report names inserting into a circular list. It leaves out the order, repeats, empty input, what to return, and how to run it. Here, the sorted cycle is given as text. Our version is about 76% the same as the reported question.

A nondecreasing circular singly linked list is serialized by one finite traversal cycle, beginning at an arbitrary node. Therefore the values have at most one descending wrap edge.

Insert insertValue while preserving the circular nondecreasing order. Duplicates are allowed. Return one traversal of the resulting cycle:

  • For a nonempty input, begin at the same original first node.
  • For an empty input, return the one-node cycle containing insertValue.

When more than one edge can accept the value, insert after the first such edge encountered from the serialized first node. The returned array lists the circular list once around the cycle.

Function

insertIntoSortedCircular(cycle: int[], insertValue: int) → int[]

Examples

Example 1

cycle = [3,4,1]insertValue = 2return = [3,4,1,2]

The traversal wraps from 4 to 1. Inserting 2 between 1 and the original first node 3 preserves circular order.

Example 2

cycle = [1,3,4]insertValue = 2return = [1,2,3,4]

The value belongs on the ordinary ascending edge from 1 to 3.

Example 3

cycle = []insertValue = 5return = [5]

An empty list becomes a one-node cycle.

Constraints

  • 0 <= cycle.length <= 200000.
  • -10^9 <= cycle[i], insertValue <= 10^9.
  • The nonempty input has at most one index i for which cycle[i] > cycle[(i + 1) % cycle.length].

More Meta Onsite Interview questions

  • Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Run-Length Encoded Vector Dot ProductPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Deterministic K-Means AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Linear Layer Forward and Backward PassesONSITE INTERVIEW · Seen Sep 2026
  • Reservoir Sampling with Recorded DrawsONSITE INTERVIEW · Seen Sep 2026
  • Stochastic Gradient Descent with MomentumONSITE INTERVIEW · Seen Sep 2026
  • Top K Largest Values with a HeapONSITE INTERVIEW · Seen Sep 2026
  • Partition a Card Deck into FifteensONSITE INTERVIEW · Seen Sep 2026
  • Maximum Stock Profit with Transaction LimitsONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • 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
  • Deep Copy a Random-Pointer ListBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Pack Stream Chunks into Fixed-Capacity NodesBroadcom Limited · ONSITE INTERVIEW
  • 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 ListSuperhuman · PHONE SCREENSuperhuman interview questions
  • Sustained Overspeed AlertsFleetx · ONSITE INTERVIEW

Interview reports that mention this question

  • Meta Software Engineer Onsite Questions: 3 Experiences

Meta interview experiences

  • Meta PhD SWE Intern AI Coding Phone Screen: 1 Experience
  • Meta Business Support Engineer Phone Screen: 1 Experience
  • Meta AI Native Engineer OA and Onsite: 1 Experience
  • Meta AI-Native Coding Interview: 3 Experiences
  • Meta Production Engineer Intern Questions: 6 Experiences
All Meta interview questionsSee Meta hiring insights
Saved
class Solution {
    public int[] insertIntoSortedCircular(int[] cycle, int insertValue) {
        // Write your code here.
    }
}
Checking account…