Answered step by step
Verified Expert Solution
Link Copied!

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


imageimage

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Managerial Economics and Organizational Architecture

Authors: James Brickley, Clifford W. Smith Jr., Jerold Zimmerman

6th edition

73523143, 73523149, 978-0073523149

More Books

Students also viewed these Programming questions

Question

Were multiple treatments used? Did they interfere with each other?

Answered: 1 week ago

Question

a. What was easy and what was difficult about this exercise?

Answered: 1 week ago