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, i.e.'[' 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 20240120221111.png]]
The strings "abcda", "abcdb", "abcdc"and "abcdd"cost 1 because the last element has a duplicate character. We
can see that the minimum cost possible is 0. Since there can be multiple possible strings with 0 cost, we choose the
lexicographically smaller one i.e. 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
1<=| data |<=105
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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!