Find the Peak of a Rise-and-Fall Array
Updated
Problem statement
You are given an integer array nums. A peak is a value that is larger than each of its neighbours. The first and last values have only one neighbour each, so the first value is a peak when it is larger than the second, and the last value is a peak when it is larger than the one before it.
In this problem the array has exactly one peak: the values strictly rise until the peak and strictly fall after it (the rising part or the falling part may be empty). Return the index of the peak.
Function
peakIndex(nums: int[]) → intExamples
Example 1
nums = [2,5,9,7,4,1]return = 2The values rise from 2 to 9 and then fall to 1. Only 9 is larger than both of its neighbours (5 and 7), and it sits at index 2.
Example 2
nums = [8,6,3]return = 0The values only fall. The first value 8 has no left neighbour and is larger than 6, so the peak is at index 0.
Example 3
nums = [-4,0,6,11]return = 3The values only rise. The last value 11 has no right neighbour and is larger than 6, so the peak is at index 3.
Constraints
1 <= nums.length <= 10^4-10^9 <= nums[i] <= 10^9nums[i] != nums[i + 1]for every validinumshas exactly one peak
More Adobe Phone Screen questions
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
- All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
- Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
- Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
- Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
- Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- Track New Values in Sorted OrderBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Price at Query TimestampsGoogle · PHONE SCREENGoogle interview questions
- First Missing Number in a Consecutive ArrayArista Networks · OA · PHONE SCREENArista Networks interview questions
- Messages in an Inclusive Timestamp RangeAttentive · PHONE SCREEN · ONSITE INTERVIEWAttentive interview questions
- First Bad Version in a Monotone ArrayMeta · PHONE SCREENMeta interview questions
- Target Sum Across Two Sorted ArraysSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Leftmost Binary Search MatchByteDance · PHONE SCREENByteDance interview questions
- Find the First Target IndexSuperhuman · PHONE SCREENSuperhuman interview questions
- First Target IndexGrammarly · PHONE SCREEN
- Ceiling Value in a Sorted ArrayPeopleStrong · PHONE SCREENPeopleStrong interview questions
Interview reports that mention this question
Adobe interview experiences
- Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
- Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
- Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
- Adobe New Grad MTS Interview Questions: 7 Experiences
- Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)