, , , , , .
, ( , / ).
, , , - . , "- ?".
O (n) :
For each index in array
coord = array[index]
if (coord == point1)
startIndex = index
if (coord == point2)
endIndex = index
if (endIndex < startIndex)
swap(startIndex, endIndex)
return array.sublist(startIndex, endIndex)
, , , , cooordinate . - :
//build the map (do this once, at init)
map = {}
For each index in array
coord = array[index]
map[coord] = index
//find a sublist (do this for each set of start/end points)
startIndex = map[point1]
endIndex = map[point2]
if (endIndex < startIndex)
swap(startIndex, endIndex)
return array.sublist(startIndex, endIndex)
O (n) , O (1). , hashmap, .
Please note that if my assumption is not fulfilled, then the same solutions are still suitable for use, provided that as the first step you take the provided start and end points and find the points in the array that best fit each of them. As already noted, if you are not given some restrictions regarding the thickness of the rope, then interpolation from an arbitrary coordinate to that which is actually part of the rope can only be a hunch at best.
source
share