SOTI interview question

Output for code and logic implementation