Skip to content

Practice Find in Mountain Array

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#1095
LeetCode Problem

Find in Mountain Array

Problem Statement

The hidden array strictly increases to one interior peak, then strictly decreases, and has at least three elements. Access it only through MountainArray.get(k), which reads zero-based position k, and MountainArray.length(), which returns its length. Return the smallest index containing target, or -1 if absent. Use at most 100 calls to get; direct array access is unavailable.

Source: Find in Mountain Array on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
mountainArr = [1,2,3,4,5,3,1], target = 3
Output
2

# Example 2

Input
mountainArr = [0,1,2,4,2,1], target = 3
Output
-1

Constraints

3 <= mountainArr.length() <= 10^4
0 <= target <= 10^9
0 <= mountainArr.get(index) <= 10^9

Related LeetCode Problems

Practice more problems similar to Find in Mountain Array.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.