#32. 数组特定位置不吉利1检查

    ID: 32 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatArray-1gesp3一维数组条件结构

数组特定位置不吉利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 11 immediately followed by a 33 in an array as an "unlucky" 11. Return true if the given array contains an "unlucky" 11 in the first 22 positions or the last 22 positions in the array. Specifically, if there exists an index ii in the array such that arr[i]=1arr[i] = 1 and arr[i+1]=3arr[i+1] = 3, and ii satisfies i=0i=0 or i=1i=1 (first 22 positions), or i=N2i=N-2 or i=N1i=N-1 (last 22 positions, where NN is the array length), then return true. Note that if the array length is less than 22, an "unlucky" 11 cannot exist. If the array length is 22, only i=0i=0 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 11 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 00, arr[0]=1arr[0]=1 and arr[1]=3arr[1]=3, which is an unlucky 11. Index 00 is among the first 22 positions, so true is returned.
  • Sample 2: The array is [2 1 3 4 5]. At index 11, arr[1]=1arr[1]=1 and arr[2]=3arr[2]=3, which is an unlucky 11. Index 11 is among the first 22 positions, so true is returned.
  • Sample 3: The array is [1 1 1]. There is no case where a 11 is immediately followed by a 33 in the array, so false is returned.

Constraints

Time limit for each test case is 11 second, and memory limit is 10241024 KiB.