Online Assessment Question (Amazon)
Anonymous User
532

Recently I gave one Online Assessment at Dare2compete There was One Question which I consider the hardest among the all three so I am sharing the hardest one Please recommend the solution for this I used Recursion which only passed few test case then memiozed it but I am not satisfied with this approach best way of solution will Highly appreciated.
So question goes like

You are given 2 integers n and m . Count all the way of sequences X of size n such that it fullfills all following 3 conditions:

  1. X[i]>=0;
  2. X[1]^X[2]^X[3]^.......^X[n]=0;
  3. X[1]+X[3]+X[3]+......+X[n]=m;

Constraints are 1<=n,m<=5000

Sample cases:

input : n=5 m=20
output : 475 { it one of sequeces is (0,0,10,10,0) }

Please do comment its solution.

Comments (1)