Find the Pivot Element
Updated
Problem statement
You are given an array nums of distinct nonnegative integers. A pivot is an element where every element to its left is strictly smaller and every element to its right is strictly greater.
Only an internal element can be a pivot, so its index must be between 1 and nums.length - 2. Return the value of the leftmost pivot. Return -1 when no pivot exists.
Function
findPivotElement(nums: int[]) → intExamples
Example 1
nums = [5,1,4,3,6,8,10,7,9]return = 6Only one internal value has every value before it smaller and every value after it greater. That value is the pivot, so the answer is 6.
Example 2
nums = [1,2,3,4,5]return = 2The values are in increasing order, so every internal value is a pivot. The leftmost pivot is the answer: 2.
Example 3
nums = [4,2,5,1,7]return = -1No internal value is greater than every value on its left and smaller than every value on its right. There is no pivot, so the answer is minus one.
Constraints
3 <= nums.length <= 20000 <= nums[i] <= 10^9- All values in
numsare distinct.
More Agoda Phone Screen questions
- Sort Ones, Twos, and Threes In PlacePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Can Place FlowersPHONE SCREEN · Seen Nov 2026
- Reverse Words in a StringPHONE SCREEN · Seen Nov 2026
- Disk Space Window AnalyzerPHONE SCREEN · Seen Sep 2026
- Shortest Subarray With the Full DegreePHONE SCREEN · Seen Sep 2026
- Enumerate Weekly Work SchedulesPHONE SCREEN · Seen Sep 2026
- Count Values Appearing Exactly OncePHONE SCREEN · Seen Sep 2026
- Longest All-Present Attendance StreakPHONE SCREEN · Seen Sep 2026
- Chemical Formula WeightPHONE SCREEN · Seen Sep 2026
- Maximum Planes Destroyed Before LandingPHONE SCREEN · Seen Jan 2026
Similar questions at other companies
- Peak Chat Load Across AgentsCresta · PHONE SCREENCresta interview questions
- Trapping Rain WaterGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- Best Improvement Period of at Least K IntervalsAmazon · PHONE SCREEN
- Majority Labels over Audio IntervalsNooks · PHONE SCREEN
- Random Pick with Weight Using Recorded DrawsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Maximum Sum Desirable SubarrayGroww · PHONE SCREEN
- Hash Partition OffsetsNVIDIA · PHONE SCREENNVIDIA interview questions
- Instrument Stack Language JumpsJane Street · PHONE SCREENJane Street interview questions
- Maximize Compatible Car RidersUber Freight · PHONE SCREEN · ONSITE INTERVIEWUber Freight interview questions
- Product of Array Except SelfCapgemini · PHONE SCREENCapgemini interview questions