Solution Count characters of each group in given string. Groups: digit, lower-case, upper-case and special characters Add one of each group to the string if not already present i.
Minimum Cost If the number of roads is zero or cost of building a road is more than cost of building a library, then building libraries in each of the cities will result in minimum cost.