Computers and Technology

Given a string, construct a new string by rearranging the original string and deleting characters as needed. Return the alphabetically largest string that can be constructed respecting a limit as to how many consecutive characters can be the same. Example:
s='bacc'
k=2
The largest string, alphabetically, is 'cccba' but it is not allowed because it uses the character 'c' more than 2 times consecutively. Therefore, the answer is 'ccbca'.
Function Description
Complete the function getLargestString in the editor below.
getLargestString has the following parameters:
string s[n]: the original string
int k: the maximum number of identical consecutive characters the new string can have
Returns:
string: the alphabetically largest string that can be constructed that has no more than k identical consecutive characters
Constraints
- 1<= n <= 10^5
- 1<= k <= 10^3
- The string s contains only lowercase English letters.
Input Format For Custom Testing
Sample Case 0
Sample Input
STDIN Function

zzzazz --> string s = 'zzzazz'
2 --> k = 2
Sample Output
zzazz
Explanation
One 'z' must be removed so that no more than 2 consecutive characters are the same.

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 19:00, jacobbecker99
Choose the correct citation for the case which established the "minimum contacts" test for a court's jurisdiction in a case. select one: a. brown v. board of education of topeka, 347 u. s. 483 (1954). b. international shoe co. v. washington, 326 u. s. 310 (1945) c. haynes v. gore, 531 u. s. 98 (2000). d. international shoe co. v. washington, 14 u. s. code 336.
Answers: 1
image
Computers and Technology, 24.06.2019 13:30, tami5
Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. the program should output the average high, average low, and the highest and lowest temper- atures for the year. your program must consist of the following functions: a. function getdata: this function reads and stores data in the two- dimensional array. b. function averagehigh: this function calculates and returns the average high temperature for the year. c. function averagelow: this function calculates and returns the aver- age low temperature for the year. d. function indexhightemp: this function returns the index of the highest high temperature in the array. e. function indexlowtemp: this function retur
Answers: 3
image
Computers and Technology, 24.06.2019 15:00, MilanPatel
In excel, what happens to the cell contents when you click and drag a cell into multiple cells?
Answers: 1
image
Computers and Technology, 25.06.2019 05:10, mathbrain58
Write a program that asks for 'name' from the user and then asks for a number and stores the two in a dictionary (called 'the_dict') as key-value pair. the program then asks if the user wants to enter more data (more data (y/n)? ) and depending on user choice, either asks for another name-number pair or exits and stores the dictionary key, values in a list of tuples and prints the list. note: ignore the case where the name is already in the dictionary. example: name: pranshu number: 517-244-2426 more data (y/n)? y name: rich number: 517-842-5425 more data (y/n)? y name: alireza number: 517-432-5224 more data (y/n)? n [('alireza', '517-432-5224'), ('pranshu', '517-244-2426'), ('rich', '517-842-5425')]
Answers: 3
Do you know the correct answer?
Given a string, construct a new string by rearranging the original string and deleting characters as...

Questions in other subjects:

Konu
Mathematics, 01.10.2019 01:00