PROBLEM LINK:
Author: Harsh Shah
Tester: Aniket Marlapalle
Editorialist: Aniket Marlapalle
DIFFICULTY:
cakewalk
PREREQUISITES:
basic-programming
PROBLEM:
You start with an empty string, you need to create the number by using one of the following 2 operations:
- You can append a digit d from 0 to 9 with a cost of d.
- Append a sub-string of current string you have with a cost of 0.
EXPLANATION:
You can observe that once a digit is appended to your string it can be appended any number of times with a cost of 0 as it will be a sub-string of the current string.
So the total cost is just the sum of distinct digits present in the string.
AUTHOR’S AND TESTER’S SOLUTIONS:
Author’s solution can be found here