Samsung Electronics Interview Question

Hard questions from Codechef.com