Regular Expression Match

Implement wildcard pattern matching with support for '?' and '*'.

  • '?' : Matches any single character.
  • '*' : Matches any sequence of characters (including the empty sequence).

The matching should cover the entire input string (not partial).

The function prototype should be:

int isMatch(const char *s, const char *p)

Examples :

isMatch("aa","a") → 0
isMatch("aa","aa") → 1
isMatch("aaa","aa") → 0
isMatch("aa", "*") → 1
isMatch("aa", "a*") → 1
isMatch("ab", "?*") → 1
isMatch("aab", "c*a*b") → 0

Return 1/0 for this problem.

NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Regular Expression Match on Interview Code Editor
Sign Up
to access hints and editorial solutions for Regular Expression Match
1353 successful submissions.
Asked In:
  • Facebook
  • Microsoft
Click here to start solving coding interview questions