histogram: stack based solution