Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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: class Solution { public String solution (String 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. Write a function: class Solution { public String solution(String 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.
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