solution for basic reduce problem