finally got recursive solution