US stocks finished the week higher, with the S&P 500 and Nasdaq ending four-week losing streaks despite renewed pressure on technology shares and persistent inflation concerns.