Huawei OD machine test real questions - Alibaba looking for a golden treasure chest (III) - 2023 OD unified test (B paper)

Title description:

The impoverished woodcutter, Ali Baba, stumbled across the treasure trove of the robber group on his way to cut firewood. The treasure trove had boxes numbered from 0 to N, and each box had a number attached to it.
Ali Baba reads a spell number to check whether there are two different boxes in the treasure chest, the numbers on the two boxes are the same, and the absolute value of the difference between the numbers of the two boxes is less than or equal to the spell number, if there is such a
pair Treasure chest, please return the number of the left chest of the pair of treasure chests found first, or return -1 if it does not exist.

Input description: Enter a string of numbers in the first line, separated by commas, for example: 1,2,3,1

The number of numbers in the string >=1, <=100000; the value of each number >=-100000, <=100000;

Enter the spell number on the second line, for example: 3, the spell number >=1, <=100000

Output description:

There is such a pair of treasure chests, please return the number of the left box of the first found pair of treasure chests, if it does not exist, return -1

Supplementary note:

Example 1

enter:

6,3,1,6
3

output:

0

illustrate:

Example 2

enter:

5,6,7,5,6,7
2

output:

-1

illustrate:

while True:
    try:
        m,k=list(

Guess you like

Origin blog.csdn.net/2301_76848549/article/details/132193806