Modified code as per requirement

- Used for in loop instead of map