IBM Interview Question

the mathematical problem, some coding questions