Added solution for medium problem