The inflation rate rose to 4.2% in May, the highest level in more than three years, as Americans continued to grapple with rising living costs.