String , XOR
Given a number N, return a String formed by the concatenation of XOR of each digit of N with digit adjacent to its right and last digit with the first one
in a cyclic way, but
for length(N)=2, return only the XOR of both digits
if length(N)=1,return the number as it is
One should take the input as String rather than Integer.Check the base/corner cases first.
- length(N)==1,return N
- length(N)==2, return XOR of both digit by explicitly casting String to Integer
Next, get an iteration form i=0 to i<length(N)-1 and print XOR of N[i] and N[i+1] again by casting them to integer, Here make sure to print the answers in the same line. Now the only thing remains is the XOR of first and last digit, print the answer in the same line
now change the line accordingly.
O(L) , Where L is the length(N)