注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
我自己OA(10/2024)做到的两道题,和之前论坛里面的题我总结了一下。
- Generate Lexicographically Smallest String
Developers at Amazon are working on a test generation utility for one of their new products.
Currently, the utility generates only speical strings. A string is special of there are no matching adajecnt characters. Given a string of length n,
generate a special string of length n that is lexicographically greater than s. If multiple such special strings are possible, then return the lexicographically smallest string among them.
Notes:
1. Special String: A string is special if there are no two adjacent characters that are the same.
2. Lexicographical Order: This is a generalization of the way words are alphabetically ordered in dictionaries. For example, "abc" is lexicographically smallest than "abd" because "c" comes before "d" in the alphabet.
A string a is lexicographically smaller than a string b if and only if one of the following holds:
1. a is a prefix of, but a is not equal to b. For example, "abc" is smaller than "abcd"
2. in the first position where a and b differ, the character in a comes before the character in b in the alphabet.;1" characters.
2. A string A is a substring of a string B if A can be obtained from B by deleting several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) chracters from the end.
Example
music = "1001"
k = 1
By flipping the third chracter, the string becomes music = "1011". The longest alternating music string in this modified string is "101", which spans from the 0th index to the 2nd index and has a length of 3. With only oen operation, it is not possible to obtain a longer alternating binary subtring. Thus, the answer is 3.
Function Description
Complete the function getMaximumAlternatingMusic.
getMaximumAlternatingMusic has the following parameters:
1. string music: a string of characters 0 and 1.
2. int k: the number of operations allowed.
如果大家觉得有用,烦请大家给个大米吧!(不会消耗自己原有大米的)!谢谢 |