Problem Link: NSTEPS – Number Steps

This problem is mostly about finding the sequence pattern. Below is my logic for the input (x,y):
1)if x and y are the same then print twice the x(or y)
2)if the difference between y and x is 2(y being larger), then check whether x is even or odd.
a)if x is odd then print x+y-1
b)else x+y
3)else no number

Link to solution: https://github.com/bharaththiruveedula/Algorithms/blob/master/SPOJ/NSTEPS.java

Advertisements