IBM interview question

Coding questions on hackerrank. couple hours to finish.