Accenture Interview Question

Hacker Rank question (Code , logic ,sql)