Added new solution using keys and foreach loop