PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000099. Tìm một đỉnh của dãy (Find Peak Element)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tìm một đỉnh của dãy (Find Peak Element)
Find Peak Element
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
A peak element is strictly greater than its immediate neighbors. Outside the array, values are conceptually . Find the zero-based index of any peak in an array with unequal adjacent elements.
Input
The first line contains ; the next line contains its integers.
Output
Print any zero-based peak index . Any valid peak is accepted.
Subtasks
- Subtask 1 (20 points): ; ; adjacent elements are unequal.
- Subtask 2 (30 points): ; ; adjacent elements are unequal.
- Subtask 3 (50 points): ; ; adjacent elements are unequal.
Examples
Input
4
1 2 3 1
Output
2
Explanation
Index has value , larger than its neighbors and ; therefore index is a valid peak.