Apple overtook Microsoft to regain its title as the world’s most valuable company, the latest sign of improving investor sentiment over its growth and position with AI.