NDS interview question

re writing the function logic