#32. 数组特定位置不吉利1检查
数组特定位置不吉利1检查
Unlucky One in Array
Background
Congcong has recently been studying number sequences. He has found that certain specific number combinations seem to carry special meanings.
Problem Description
We define a immediately followed by a in an array as an "unlucky" . Return true if the given array contains an "unlucky" in the first positions or the last positions in the array.
Specifically, if there exists an index in the array such that and , and satisfies or (first positions), or or (last positions, where is the array length), then return true.
Note that if the array length is less than , an "unlucky" cannot exist. If the array length is , only satisfies the condition.
Input Format
The input consists of a single line representing an array of integers. Array elements are separated by spaces.
arr
Output Format
Output a single line. If the array contains an unlucky that meets the conditions, output true; otherwise, output false.
result
Sample
[1 3 4 5]
true
[2 1 3 4 5]
true
[1 1 1]
false
Sample Explanation
- Sample 1: The array is
[1 3 4 5]. At index , and , which is an unlucky . Index is among the first positions, sotrueis returned. - Sample 2: The array is
[2 1 3 4 5]. At index , and , which is an unlucky . Index is among the first positions, sotrueis returned. - Sample 3: The array is
[1 1 1]. There is no case where a is immediately followed by a in the array, sofalseis returned.
Constraints
Time limit for each test case is second, and memory limit is KiB.