Here, in this method, we will solve this problem using a odd and even pattern. And, we will check if the given x,y points lies on line x=y or x-y=2 */
| 7 | And, we will check if the given x,y points lies on line x=y or x-y=2 |
| 8 | */ |
| 9 | int solve(int x, int y){ |
| 10 | if(x-y==0 && y%2==0){ //line is x=y and even pattern |
| 11 | return y*2; |
| 12 | } |
| 13 | else if(x-y ==0 && y%2 !=0 ){ //line is x=y and odd pattern |
| 14 | return (y-1)*2 + 1; |
| 15 | } |
| 16 | else if(x-y == 2 && y%2 != 0){ //line is x-y=2 and odd pattern |
| 17 | return y*2 + 1; |
| 18 | } |
| 19 | else if(x-y == 2 && y%2 == 0){ //line is x-y=2 and even pattern |
| 20 | return y*2 + 2; |
| 21 | } |
| 22 | else return -1; //no point is there |
| 23 | } |
| 24 | int main() |
| 25 | { |
| 26 | jaadu; |