Solution for the interview problem posted by Eka