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, 23.06.2019 00:00
Donna and her team of five have invented a new gadget for the science exhibition in their college. which intellectual property right will protect their invention?
Answers: 1
question
Computers and Technology, 23.06.2019 09:30
Why is an outfitting a workspace with video games in a technology development company considered a strategic use of money
Answers: 1
question
Computers and Technology, 23.06.2019 17:00
What are the 12 colors of the spectrum called?
Answers: 1
question
Computers and Technology, 23.06.2019 18:00
Freya realizes she does not have enough in her bank account to use the debit card. she decides to use a credit card instead. which questions should freya answer before using a credit card? check all that apply. can i pay at least the minimum payment each month? can i make payments on time and avoid late fees? will i have to take out a loan? how much in finance charges can i afford to pay? should i talk to a consumer credit counseling service?
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
Mathematics, 28.04.2021 16:10
question
Mathematics, 28.04.2021 16:10
question
Law, 28.04.2021 16:10