Computer Science, asked by kk30654, 6 hours ago

You are currently at cell (1, 1) of an N X M grid. There is a rule that decides how you can move in the grid to reach the position (N, M). The rule is, that if you are at cell (x, y) then from there you can either move to cell (x, x+y) or to cell (x+y, y) in one step Your task is to find the minimum number of steps that you must take to reach cell (N, M) starting from current position i.e. (1,1) Note: If it is not possible to reach (N. M) from (1, 1), then return-1 as your output 11 Ca Input Specification: input1: An integer value representing the value of N where 1​

Answers

Answered by mk6690642
8

Answer:

Input: points[] = [(0, 0), (1, 1), (1, 2)]

Output: 2

Move from (0, 0) to (1, 1) in 1 step(diagonal) and

then from (1, 1) to (1, 2) in 1 step (rightwards)

Input: points[] = [{4, 6}, {1, 2}, {4, 5}, {10, 12}]

Output: 14

Move from (4, 6) -> (3, 5) -> (2, 4) -> (1, 3) ->

(1, 2) -> (2, 3) -> (3, 4) ->

(4, 5) -> (5, 6) -> (6, 7) ->

(7, 8) -> (8, 9) -> (9, 10) -> (10, 11) -> (10, 12)

Similar questions