FastPrepShortest Subarray to Sort
Problems/Shortest Subarray to Sort

Shortest Subarray to Sort

Expedia logoExpedia● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: In the report's example the window has length 6, but it printed length 5. We corrected that. We chose the limits and what happens when the array is already sorted. Our version is about 98% the same as the reported question.

Return the length of the shortest contiguous subarray of values that can be sorted in nondecreasing order to make the entire array nondecreasing. Return 0 when it is already sorted.

Function

shortestUnsorted(values: int[]) → int

Examples

Example 1

values = [10,12,20,30,25,40,32,31,35,50,60]return = 6

Sorting indices 3..8 changes [30,25,40,32,31,35] to [25,30,31,32,35,40], making the complete array sorted.

Example 2

values = [1,2,2,3]return = 0

The array is already nondecreasing.

Constraints

  • 1 <= values.length <= 10000.
  • -1000000000 <= values[i] <= 1000000000.

More Expedia Onsite Interview questions

  • Scramble StringONSITE INTERVIEW · Seen Sep 2026
  • Smallest Sufficient TeamONSITE INTERVIEW · Seen Sep 2026
  • Check Anagram Pairs Index by IndexONSITE INTERVIEW · Seen Oct 2025
  • Fresh Oranges Left After Rotting StopsONSITE INTERVIEW · Seen Oct 2025
  • Longest Increasing SubsequenceONSITE INTERVIEW · Seen Oct 2025
  • Lowest Common Ancestor with Repeated and Missing ValuesONSITE INTERVIEW · Seen Oct 2025
  • Shortest Substring with Exactly K OnesONSITE INTERVIEW · Seen Oct 2025
  • Middle Element of a Linked ListONSITE INTERVIEW · Seen Nov 2024
  • Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
  • Mirror Image Binary TreesONSITE INTERVIEW · Seen Sep 2024

Similar questions at other companies

  • Search a Row- and Column-Sorted MatrixByteDance · ONSITE INTERVIEWByteDance interview questions
  • Shortest Window with Required CountsOracle · ONSITE INTERVIEWOracle interview questions
  • 3Sum SmallerSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Sort Ones, Twos, and Threes In PlaceAgoda · PHONE SCREEN · ONSITE INTERVIEWAgoda interview questions
  • Minimum Station Tracks for a Train ScheduleBNSF Railway · ONSITE INTERVIEWBNSF Railway interview questions
  • Candy Crush Grid Matching and GravityRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • Longest Binary Window with at Most K OnesLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • Rotate an Array Right by K StepsQualys · ONSITE INTERVIEWQualys interview questions
  • Find the Duplicate NumberWalmart Labs · ONSITE INTERVIEW
  • Two or Three Sum ExistenceGoogle · ONSITE INTERVIEWGoogle interview questions

Interview reports that mention this question

  • Expedia New Grad SDE Earlier Loops: 5 Experiences (Part 2 of 3)

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)
All Expedia interview questionsSee Expedia hiring insights
Saved
class Solution {
    public int shortestUnsorted(int[] values) {
        // Write your code here.
    }

}
Checking account…