Find in Mountain Array
Updated
Problem statement
A mountain array strictly increases to one peak and then strictly decreases.
Given a mountain array mountain and an integer target, return the smallest index whose value equals target. Return -1 when the target is absent.
Your algorithm must use logarithmic-time binary searches rather than scanning the array.
Function
findInMountainArray(mountain: int[], target: int) → intExamples
Example 1
mountain = [1,2,3,4,5,3,1]target = 3return = 2Value 3 appears on both slopes; return its smaller index 2.
Example 2
mountain = [0,1,2,4,2,1]target = 3return = -1The target is absent.
Example 3
mountain = [1,5,2]target = 5return = 1The target is the peak.
Constraints
3 <= mountain.length <= 100000.-10^9 <= mountain[i], target <= 10^9.- There is exactly one peak, with at least one value on each side.
- The left slope is strictly increasing and the right slope is strictly decreasing.
More Bloomberg LP Onsite Interview questions
- Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Shortest Subarray with Sum at Least KOracle · ONSITE INTERVIEWOracle interview questions
- Russian Doll EnvelopesGoogle · ONSITE INTERVIEWGoogle interview questions
- K-th Element of Two Sorted ArraysFlipkart · ONSITE INTERVIEW
- Allocate Minimum PagesAmazon · ONSITE INTERVIEW
- Minimum Processing Speed with Multiple RidersDoorDash · ONSITE INTERVIEWDoorDash interview questions
- Russian Doll EnvelopesInMobi · ONSITE INTERVIEWInMobi interview questions
- Median of Two Sorted ArraysRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Median of Two Sorted ArraysMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Russian Doll EnvelopesAirbnb · ONSITE INTERVIEWAirbnb interview questions
- Median of Two Sorted ArraysExpedia · ONSITE INTERVIEWExpedia interview questions
Bloomberg LP interview experiences
- Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
- Bloomberg SWE Intern Interview Questions: 68 Questions
- Bloomberg Interview Questions, Level Not Reported: 65 Questions
- Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
- Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
- Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)