Pergunta de entrevista da empresa IBM

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