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 9244805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:07:23+00:00 2026-06-18T09:07:23+00:00

I recently had an interview with Google for a Software Engineering position and the

  • 0

I recently had an interview with Google for a Software Engineering position and the question asked regarded building a pattern matcher.

So you have to build the

boolean isPattern(String givenPattern, String stringToMatch)

Function that does the following:

givenPattern is a string that contains:

a) 'a'-'z' chars
b) '*' chars which can be matched by 0 or more letters
c) '?' which just matches to a character - any letter basically

So the call could be something like

isPattern("abc", "abcd") – returns false as it does not match the pattern (‘d’ is extra)

isPattern("a*bc", "aksakwjahwhajahbcdbc"), which is true as we have an ‘a’ at the start, many characters after and then it ends with “bc”

isPattern("a?bc", "adbc") returns true as each character of the pattern matches in the given string.

During the interview, time being short, I figured one could walk through the pattern, see if a character is a letter, a * or a ? and then match the characters in the given string respectively. But that ended up being a complicated set of for-loops and we didn’t manage to come to a conclusion within the given 45 minutes.

Could someone please tell me how they would solve this problem quickly and efficiently?

Many thanks!

  • 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-06-18T09:07:24+00:00Added an answer on June 18, 2026 at 9:07 am
    boolean isPattern(String givenPattern, String stringToMatch) {
        if (givenPattern.empty)
            return stringToMatch.isEmpty();
        char patternCh = givenPatter.charAt(0);
        boolean atEnd = stringToMatch.isEmpty();
        if (patternCh == '*') {
            return isPattenn(givenPattern.substring(1), stringToMatch)
                || (!atEnd && isPattern(givenPattern, stringToMatch.substring(1)));
        } else if (patternCh == '?') {
            return !atEnd && isPattern(givenPattern.substring(1), 
                stringToMatch.substring(1));
        }
        return !atEnd && patternCh == stringToMatch.charAt(0)
              && isPattern(givenPattern.substring(1), stringToNatch.subtring(1);
    }
    

    (Recursion being easiest to understand.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently had an interview with a reputable company for the position of Software
Recently i had an interview in which the question was asked as How would
Recently I had a question on the interview - I was asked to compare
This task has already been asked/answered, but I recently had a job interview that
I recently had this question in an interview and this is what I came
I had an interview recently and he asked me about Singleton Design Patterns about
I had a C++ interview recently where I was asked, how does the compiler
I had an interview recently where I was asked to produce the traditional FizzBuzz
I'm struggling with an interview question I had recently. 3 dimension tables (Product, Store
I recently had an interview question where I had to implement memcpy. I've used

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.