Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 279475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:02:08+00:00 2026-05-12T05:02:08+00:00

Im having difficulty finding an algorithm for the following puzzle- A string is called

  • 0

Im having difficulty finding an algorithm for the following puzzle-
A string is called ugly if it has 3 vowels in a row, or 5 consonants in a row, or both. A string is called nice if it is not ugly. You are given a string s, consisting of uppercase letters (‘A’-‘Z’) and question marks (‘?’).
Can you find an algorithm that tells if the string can be made nice by substituting the question marks with alphabets?

Example –

  1. “EE?FFFF” – Cant be made nice. Inserting either a consonant or a vowel would make it ugly.

  2. “H??LOWOR??” – Can be made nice.

P.S – Not homework, but a part of a programming puzzle on the internet.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:02:09+00:00Added an answer on May 12, 2026 at 5:02 am

    Note that the only strings that might potentially be ugly are those that are already ugly by virtue of the given letters or those which contain only singleton question marks. Here’s the sketch of the proof:

    • For any set of two question marks, make the left question mark the opposite of the left neighbor and the right question mark the opposite of the right neighbor. E.g. V??C should become VCVC. Such a substitution can never turn a string ugly if it was not already ugly.
    • For any set of three or more question marks, set the leftmost and rightmost question marks as above and then alternate the middle question marks between V and C. This might result in introducing two consecutive V’s or C’s, but never three.

    So, we’re left with two simple cases.

    • Checking if a string is already ugly is a straightforward regex.
    • The only scenario in which a singleton can turn a string ugly is if the question mark has two vowels to one side and four consonants to the other side; but you can’t just check for those, as substitution might introduce such patterns (consider EE?FFF?EE). But at this point, you can check by working from left to right, resolving each singleton question mark by inserting the opposite of the right neighbor unless that would turn the string ugly and stopping if the two vowel / four consonant pattern is present.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've stumbled on this algorithm recently and am having difficulty explaining it to myself.
I'm currently having difficulty finding a way of making my loops work. I have
I am working on creating a python c extension but am having difficulty finding
There is probably a really straightforward answer to this but I'm having difficulty finding
I'm working with Views 2 in Drupal 6, and I am having difficulty finding
Having difficulty articulating this correlated subquery. I have two tables fictitious tables, foo and
I am having difficulty reliably creating / removing event sources during the installation of
I'm having difficulty parsing some JSON data returned from my server using jQuery.ajax() To
I am having difficulty determining if the body of a text email message is
I'm having difficulty searching for this. How would I define an element in an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.