#219. 数组递归查找倍数

    ID: 219 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatWarmup-2gesp5递归一维数组

数组递归查找倍数

Array Multiple Search

Background

This is an exercise problem about recursion and array traversal.

Problem Description

Given an array of integers, compute recursively if the array contains somewhere a value followed in the array by that value times 1010. We'll use the convention of considering only the part of the array that begins at the given index. In this way, a recursive call can pass index+1index+1 to move down the array. The initial call will pass in indexindex as 00.

Input Format

Input is given from standard input in the following format.

A single line containing an integer array (enclosed in square brackets, elements separated by spaces) and an integer indexindex.

Output Format

Output to standard output in the following format.

Output true if such a value exists; otherwise, output false.

Sample

[1 2 20] 0
true
[3 30] 0
true
[3] 0
false

Sample Explanation

Sample 1: For array [1, 2, 20] and starting index 00.

  • When index=0index = 0, `arr[0] = 1$. There is no 10×1=1010 \times 1 = 10 after 11 in the array.
  • When index=1index = 1, arr[1] = 2$. There is $10 \times 2 = 20$ after $2$ in the array (i.e., arr[2]). Thus, true` is returned.

Sample 2: For array [3, 30] and starting index 00.

  • When index=0index = 0, arr[0] = 3$. There is $10 \times 3 = 30$ after $3$ in the array (i.e., arr[1]). Thus, true` is returned.

Sample 3: For array [3] and starting index 00.

  • When index=0index = 0, arr[0] = 3$. There is no $10 \times 3 = 30$ after $3$ in the array. The array ends, thus false` is returned.

Constraints

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