if no follow-up, this is the best solution. I know what the OP is going about, but this would be a faster solution. from typing and execution both. if someone writes this and when the interviewer adds the extendability and other dynamic nature to the question can make it to the two for-loop...