Teranet interview question

Regarding coding logics. Also some test cases