Nifty ends higher led by auto, IT stock gains, midcaps outperform