Algorithm · Karat · Hard
A room is described by a string. Each uppercase letter in the string marks a sphere, and each lowercase letter marks a hole; a letter's identity indicates its color, so a sphere and a hole share a color when they are the same letter in different cases. Every sphere must be moved into a hole that matches its color, and you can carry only one sphere at any moment. Compute and return the smallest total distance that must be traveled to deliver all of the spheres into holes of…