Help needed in this problem (don't know the source)

Revision en2, by psywoo, 2022-03-27 09:07:12

Problem :

**You are standing at point (0 , 0). You can move to any point with integer coordinates that is exactly K units away in terms of manhattan distance from the point you are currently standing at. For eg : K = 3 , and you are standing at ( 4, -3) you can go to ( 5 , -5 ) or ( 4 , 0 ) as they both are at a manhattan distance of K (note that there are other options too).

You need to answer the minimum number of moves required to reach point (x , y) or say its impossible to reach (x , y)**

Constraints :

-1e5 <= x , y <= 1e5

1 <= K <= 1e9

Sample TC : K = 3

pt = ( 1 , 3 )

output : 2

explanation : In one move you can go from (0 , 0) to (-3 , 2) Distance = |0 — (-3)| + |0 — 2| = 5 , and then from (-3, 2) you can go to (1 , 3) Distance = |-3 — 1| + |2 — 3| = 5 . So 2 moves is the minimum answer.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English psywoo 2022-03-27 09:07:56 4
en2 English psywoo 2022-03-27 09:07:12 1 Tiny change: 'ch (x , y) **\n\nCons' -> 'ch (x , y)**\n\nCons'
en1 English psywoo 2022-03-27 09:06:17 924 Initial revision (published)