cswork / OA打开练习工作台

BoxOA #3

Box Fro~yo

简单可在线判题

考点(AI 标注)原地数组

Given a circularly arranged array of flavors, the current position startIndex, and the target flavor target, find the minimum number of steps needed to move left or right to the target flavor. If the target flavor appears multiple times, choose the nearest one.

输入格式

A single line containing a JSON object with flavors (a non-empty array of strings), startIndex (starting from 0), and target (a flavor name that appears in the array).

输出格式

Output the minimum number of left/right moves needed to reach any position holding the target flavor.

样例 1

输入:

{"flavors": ["originalart", "banana", "custard", "mango"], "startIndex": 1, "target": "originalart"}

输出:

1

样例 2

输入:

{"flavors": ["originalart", "banana", "custard", "mango"], "startIndex": 1, "target": "banana"}

输出:

0

样例 3

输入:

{"flavors": ["a", "b", "c", "d", "e"], "startIndex": 4, "target": "b"}

输出:

2

样例 4

输入:

{"flavors": ["a", "b", "c", "d", "e"], "startIndex": 0, "target": "d"}

输出:

2

样例 5

输入:

{"flavors": ["only"], "startIndex": 0, "target": "only"}

输出:

0

样例 6

输入:

{"flavors": ["x", "target", "a", "target", "y"], "startIndex": 0, "target": "target"}

输出:

1

样例说明

Note: the explanation of the source example clearly specifies the target as originalart, so the candidate only corrects target=banana in the example to originalart; if the original input kept banana, the correct answer would be 0.