M
M
MaxLich2018-07-04 09:22:33
Java
MaxLich, 2018-07-04 09:22:33

How to understand the condition of the problem?

Hello. The task:

Consider the leftmost and rightmost appearances of some value in an array. We'll say that the "span" is the number of elements between the two inclusive. A single value has a span of 1. Returns the largest span found in the given array. (Efficiency is not a priority.)

I can't figure out what to do. I can't figure out what "span" is.
ZY Examples for the task are given:
maxSpan([1, 2, 1, 1, 3]) → 4
maxSpan([1, 4, 2, 1, 4, 1, 4]) → 6
maxSpan([1, 4, 2, 1, 4, 4 , 4]) → 6

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2018-07-04
@MaxLich

The number of elements between two extreme identical elements, including themselves.

S
Sergey Sokolov, 2018-07-04
@sergiks

In this problem, "span" is the extent, the length of the segment.
In the example, 1, 2, 1, 1, 3this is the distance between the leftmost unit and the rightmost unit, including the ends. The position of the rightmost (3) minus the position of the leftmost (0) plus 1.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question