Stocks posted their best week since November, led by gains in tech companies, as strong earnings and easing inflation helped drive momentum.