Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started