Virtusa | Online Test | Number of Sequences

you are given values of N and M, where N is the position of house at where police is currently at and M is the position of house where thief is residing. you are starting from N and when you are at a position currently at k ,you are allowed to go position (k+1) or (k+M/2)%M.you have to tell the number of sequences that are there to reach the thief who is at position M starting from N.

Note : you are not allowed to visit the same house more than once

M will be always greater than N

Input: N = 2 M = 3
Output : 1

Explanation: The only sequence exists is 2 -> 3

Input : N=2 M=4
Output : 2

Explanation: There are two such sequences exists

sequence 1: 2->3->4
sequence 2: 2->0->1->3->4

Please provide the approach or solution to this problem below

Comments (1)