D) Find K
Simulate with sample examples
Assume the array given was [A,B,C,D] what would be the pattern when you simulate it?
what if we deleted the variables in consecutive order like element at index 0 first then element at index 1, ... element at index — 1.
let say we are given an array [A,B,C,D] when we delete in consecutive order to see the pattern: * first we delete A and subtract from the rest [B — A, C — A, D — A] * Then we delete the next sequence which is B — A [C — A — (B — A), D — A — (B — A)] which simplifies to [C- B, D — B] * Finally we delete the next sequence which is C — B [D — B — (C — B)] which simplifies to [D — C]
So we can see that we only need two number whose difference is equal to k. so basically we need to find two numbers that meet the condition and print YES and if we can't get print NO.