Teranet Interview Question

Regarding coding logics. Also some test cases