Question: Given the string data, interpolate the data such that the total cost of all the indices is minimized. If there are multiple ways to get
Given the string data, interpolate the data such that the total cost of all the indices is minimized. If there are
multiple ways to get minimum cost, print the lexicographically smallest possible string that satisfies the goal.
Note: A string p is lexicographically smaller than string q if p is a prefix of q is not equal to q or there exists i such
that pi q and for all j i it is satisfied that pj qj Note that while comparing pjand qjwe consider their ASCII
values, ie and are greater than any uppercase English letters. For example, "ABC" is lexicographically smaller
than BCD and "ABCDE" but larger than "AAC" and "AACDE".
Example
Given the string data "abcd?"
Pasted image png
The strings "abcda", "abcdb", "abcdc"and "abcdd"cost because the last element has a duplicate character. We
can see that the minimum cost possible is Since there can be multiple possible strings with cost we choose the
lexicographically smaller one ie abcde.
Function Description
Complete the function getMinCostData in the editor below.
getMinCostData has the following parameter:
data: a string
Returns
string: the lexicographically minimum string with the minimum cost
Constraints
data
It is guaranteed that s contains at least one character and others are lowercase English letters or the character
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
