Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Palindrome With Wildcards

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Palindrome With Wildcards. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Bentley iTwin model metadata may contain unknown characters represented by ?. Return "yes" if the string can be made into a palindrome by replacing each ? with any single character, or return "no" otherwise.

A replacement must be consistent only within its mirrored position. Different wildcards may be replaced with different characters. Characters that are not ? cannot be changed.

Formal Specification

Implement can_be_palindrome(s), where s is a string. Return the string "yes" when at least one valid palindrome can be formed, and "no" otherwise. The input contains lowercase English letters and ? characters.

Constraints

  • 1 <= len(s) <= 10^5
  • s contains only lowercase English letters and '?'
  • Each '?' can be replaced by any single lowercase English letter

Function Signature

def can_be_palindrome(s):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output