IBM Interview Question

first question is very complex there may be more then ten testcases.