A local charity is asking for donations of Ethernet cable.
You realize that you probably have a lot of extra cable in your house, and make the decision that
you will donate as much cable as you can spare.
You will be given a String lengths indicating the length (in meters) of cables
between each pair of rooms in your house.
You wish to keep only enough cable so that every pair of rooms in your house is connected by some
chain of cables, of any length.
The jth character of lengths[i] gives the length of the cable between
rooms i and j in your house.
A value of '0' (zero) indicates no cable,
values of 'a' through 'z' indicate lengths of 1 through 26,
and values of 'A' through 'Z' indicate lengths of 27 through 52.
If both the jth character of lengths[i]
and the ith character of lengths[j] are greater than 0,
this means that you have two cables
connecting rooms i and j, and you can certainly donate at least one of them.
If the ith character of lengths[i] is greater than 0,
this indicates unused cable in room i,
which you can donate without affecting your home network in any way.
You are not to rearrange any cables in your house; you are only to remove unnecessary ones.
Return the maximum total length of cables (in meters) that you can donate.
If any pair of rooms is not initially connected by some path, return -1.