solved problem1 using hs