subject

Rick is a fan of logic-based games. However, he is bored of the classic ones, like Sudoku and Mastermind, since he has solved so many of them. Recently he found a new game in which one is given a string with some question marks in it. The objective is to replace all of the question marks with letters (one letter per question mark) in such a way that no letter appears next to another letter of the same kind. Write a function:
def solution(riddle)
that, given a string riddle, returns a copy of the string with all of the question marks replaced by lowercase letters (a-z) in such a way that the same letters do not occur next to each other. The result can be any of the possible answers as long as it fulfils the above requirements.
Examples:
1. Given riddle = "ab?ac?", your function might return "abcaca". Some other possible results are 'abzacd", "abfacf".
2. Given riddle = "rd?e?wg??", your function might return "rdveawgab".
3. Given riddle = "", your function might return "codility".
Write an efficient algorithm for the following assumptions:
• the length of the string is within the range [1..100,000);
• string riddle consists only of lowercases letters (a - z) or '?';
• it is always possible to turn string 'riddle' into a string without two identical consecutive letters.
1 # you can write to stdout for debugging purposes, e. g.
2 # print("this is a debug message")
3
4 def solution (riddle):
5
6 # write your code in Python 3.6
7 pass

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 08:10
Alook-up table used to convert pixel values to output values on a monitor. essentially, all pixels with a value of 190 or above are shown as white (i.e. 255), and all values with a value of 63 or less are shown as black (i.e. 0). in between the pixels are scaled so that a pixel with a value p is converted to a pixel of value 2/127 −+3969). if a pixel has a value of 170 originally, what value will be used to display the pixel on the monitor? if a value of 110 is used to display the pixel on the monitor, what was the original value of the pixel?
Answers: 1
question
Computers and Technology, 22.06.2019 13:30
Use the keyword strategy to remember the meaning of the following word. the meaning for the word has been provided. write your keyword and describe the picture you would create in your mind. centurion: a commander in the army of ancient rome. keyword: picture:
Answers: 2
question
Computers and Technology, 22.06.2019 22:40
Least square fit to polynomial write a function leastsquarefit3pol that solves a linear system of equations to find a least squares fit of a third order polynomial to an experimental data set given as two row arrays. the function leastsquarefit3pol must explicitly solve a set of linear equations and cannot use polyfit. there should be no restriction on the size of the problem that can be solved.
Answers: 1
question
Computers and Technology, 23.06.2019 04:31
Which of the following is not a way in which trees benefit the environment? a. they remove a significant amount of carbon dioxide from the atmosphere. b. they remove a significant amount of oxygen from the atmosphere. c. their roots hold soil in place, reducing rates of erosion. d. they remove ozone and particulates from the atmosphere. select the best answer from the choices provided a b c d
Answers: 1
You know the right answer?
Rick is a fan of logic-based games. However, he is bored of the classic ones, like Sudoku and Master...
Questions
question
History, 12.05.2021 22:00
question
Mathematics, 12.05.2021 22:00
Questions on the website: 13722367