Adobe Interview Question for Computer Scientists


Country: United States




Comment hidden because of low score. Click to expand.
1
of 1 vote

bool match(char *pattern, char *st) {
	if (*pattern == 0) return *st == 0;
	
	switch (*pattern) {
		case '?' :
			return *st ? match(pattern+1, st+1) : false;
			
		case '*' :
			if (pattern[1] == 0) return true;
			while (*st)
				if (match(pattern+1, st++))
					return true;
			return false;
			
		default: return *st
					? *pattern == *st && match(pattern+1, st+1)
					: false;
	}
}

- nikolay.dimitrov April 17, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/* 	? replaces one character
	* replaces zero or more characters
*/
int wildmatch(char* s, char *p){
	if(s[0]==0 && p[0]==0) return 1;
	else if(s[0]==0){
		while(p[0]=='*')p++;
		if(p[0]!=0)return -1;
		else return 1;
	}
	else if(p[0]==0)return 0;
	
	if(p[0]==s[0] || p[0]=='?')
		return wildmatch(s+1,p+1);
	else if(p[0]=='*'){
	    if(p[1]==0)return 1;
	    int ret=0;
	    int i=0;
	    while(ret==0){
	        ret=wildmatch(s+i,p+1);
	        i++;
	    }
	    if(ret==-1) return -1;
	    else return 1;
	}
	else return 0;
}

- alex.pavlovic April 15, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/* 	? replaces one character
	* replaces zero or more characters
*/
int wildmatch(char* s, char *p){
	if(s[0]==0 && p[0]==0) return 1;
	else if(s[0]==0){
		while(p[0]=='*')p++;
		if(p[0]!=0)return -1;
		else return 1;
	}
	else if(p[0]==0)return 0;
	
	if(p[0]==s[0] || p[0]=='?')
		return wildmatch(s+1,p+1);
	else if(p[0]=='*'){
	    if(p[1]==0)return 1;
	    int ret=0;
	    int i=0;
	    while(ret==0){
	        ret=wildmatch(s+i,p+1);
	        i++;
	    }
	    if(ret==-1) return -1;
	    else return 1;
	}
	else return 0;
}

- alex.pavlovic April 15, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

wildmatch (agcbc, a*b?)=1

bool wildmatch (char *string, char *pattern):
     if (*pattern == ‘\n’ && *string == ‘\n') {
           return true;
     }
     if (*string == ‘\n') {
           return false;
     }
     if (*pattern == *string || *pattern = ‘?') {
          wildmatch (string++, pattern++);
     }
     while (*pattern == ‘*’) {
          pattern++;
     }
     while (*string != *pattern && *string != ‘\n') {
           string++;
     }
     wildmatch (string, pattern);
}

- Anonymous April 15, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

My own approach to the problem is to construct a grammar such as

Pattern = [Token] * Pattern |
                [Token] ? Pattern |
                [Token]

Token = all chars except * and ?

- zsalloum April 15, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Given:

? - any char
* - any string

wildmatch (agcbc, a*ba) is supposed to return 0, isn't it?

- Marcello Ghali April 15, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yes, It should be 0. I think he wanted to type a*b?. In that case it would be 1.

- nishant.cena May 26, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool wildmatch(string s,string sPattern)
{
	if(s.length() == 1 && sPattern.length() == 1 && s[0] == sPattern[0])
		return true;
 
	if(s.length() == 1 || sPattern.length() == 1)
		return false;
	 
	if((s[0] == sPattern[0]) || sPattern[0] == '?')
	{
		return wildmatch(s.substr(1),sPattern.substr(1));
	}
	else if(sPattern[0] == '*' && s[0] != sPattern[1])
	{
	 	return wildmatch(s.substr(1),sPattern);	
	}else if(sPattern[0] == '*' && s[0] == sPattern[1])
	{
		return wildmatch(s.substr(1),sPattern.substr(2));
	}

	return false;
}

- Alex April 15, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

static boolean wildMatchRecursive(String pattern, String s){

if((pattern.length()==1 && s.length()==1) && (pattern.charAt(0)==s.charAt(0) || pattern.charAt(0)=='?')){

return true;
}
if(pattern.length()==1 && pattern.charAt(0)=='*'){

return true;
}
if(pattern.length()==1 && pattern.charAt(0)=='?'){
return false;
}

if(pattern.length()==1 && s.length()==1){

return false;
}


if(pattern.charAt(0)==s.charAt(0) || pattern.charAt(0)=='?'){

return wildMatchRecursive(pattern.substring(1), s.substring(1));
}else if(pattern.charAt(0)=='*'){

System.out.println("$$ " + s.substring(s.indexOf((pattern.charAt(pattern.indexOf('*')+1)))));
//return wildMatchRecursive(pattern.substring(pattern.indexOf('*')+1),s.substring(s.length()-(pattern.substring(pattern.indexOf('*')+1)).length()));
return wildMatchRecursive(pattern.substring(pattern.indexOf('*')+1),s.substring(s.indexOf((pattern.charAt(pattern.indexOf('*')+1)))));
}


return false;


}

- Eshwar April 16, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

static boolean wildMatchRecursive(String pattern, String s){

if((pattern.length()==1 && s.length()==1) && (pattern.charAt(0)==s.charAt(0) || pattern.charAt(0)=='?')){

return true;
}
if(pattern.length()==1 && pattern.charAt(0)=='*'){

return true;
}
if(pattern.length()==1 && pattern.charAt(0)=='?'){
return false;
}

if(pattern.length()==1 && s.length()==1){

return false;
}


if(pattern.charAt(0)==s.charAt(0) || pattern.charAt(0)=='?'){

return wildMatchRecursive(pattern.substring(1), s.substring(1));
}else if(pattern.charAt(0)=='*'){

System.out.println("$$ " + s.substring(s.indexOf((pattern.charAt(pattern.indexOf('*')+1)))));
//return wildMatchRecursive(pattern.substring(pattern.indexOf('*')+1),s.substring(s.length()-(pattern.substring(pattern.indexOf('*')+1)).length()));
return wildMatchRecursive(pattern.substring(pattern.indexOf('*')+1),s.substring(s.indexOf((pattern.charAt(pattern.indexOf('*')+1)))));
}


return false;


}

- Eshwar April 16, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

static boolean wildMatchRecursive(String pattern, String s){

if((pattern.length()==1 && s.length()==1) && (pattern.charAt(0)==s.charAt(0) || pattern.charAt(0)=='?')){

return true;
}
if(pattern.length()==1 && pattern.charAt(0)=='*'){

return true;
}
if(pattern.length()==1 && pattern.charAt(0)=='?'){
return false;
}

if(pattern.length()==1 && s.length()==1){

return false;
}


if(pattern.charAt(0)==s.charAt(0) || pattern.charAt(0)=='?'){

return wildMatchRecursive(pattern.substring(1), s.substring(1));
}else if(pattern.charAt(0)=='*'){

System.out.println("$$ " + s.substring(s.indexOf((pattern.charAt(pattern.indexOf('*')+1)))));
//return wildMatchRecursive(pattern.substring(pattern.indexOf('*')+1),s.substring(s.length()-(pattern.substring(pattern.indexOf('*')+1)).length()));
return wildMatchRecursive(pattern.substring(pattern.indexOf('*')+1),s.substring(s.indexOf((pattern.charAt(pattern.indexOf('*')+1)))));
}


return false;


}

- Eshwar April 16, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

static boolean wildMatchRecursive(String pattern, String s){

if((pattern.length()==1 && s.length()==1) && (pattern.charAt(0)==s.charAt(0) || pattern.charAt(0)=='?')){

return true;
}
if(pattern.length()==1 && pattern.charAt(0)=='*'){

return true;
}
if(pattern.length()==1 && pattern.charAt(0)=='?'){
return false;
}

if(pattern.length()==1 && s.length()==1){

return false;
}


if(pattern.charAt(0)==s.charAt(0) || pattern.charAt(0)=='?'){

return wildMatchRecursive(pattern.substring(1), s.substring(1));
}else if(pattern.charAt(0)=='*'){

System.out.println("$$ " + s.substring(s.indexOf((pattern.charAt(pattern.indexOf('*')+1)))));
//return wildMatchRecursive(pattern.substring(pattern.indexOf('*')+1),s.substring(s.length()-(pattern.substring(pattern.indexOf('*')+1)).length()));
return wildMatchRecursive(pattern.substring(pattern.indexOf('*')+1),s.substring(s.indexOf((pattern.charAt(pattern.indexOf('*')+1)))));
}


return false;


}

- Eshwar April 16, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

static boolean wildMatchRecursive(String pattern, String s){

if((pattern.length()==1 && s.length()==1) && (pattern.charAt(0)==s.charAt(0) || pattern.charAt(0)=='?')){

return true;
}
       if(pattern.length()==1 && pattern.charAt(0)=='*'){

return true;
}
      if(pattern.length()==1 && pattern.charAt(0)=='?'){
   return false;
     }

if(pattern.length()==1 && s.length()==1){

return false;
}


if(pattern.charAt(0)==s.charAt(0) || pattern.charAt(0)=='?'){

return wildMatchRecursive(pattern.substring(1), s.substring(1));
}else if(pattern.charAt(0)=='*'){

System.out.println("$$  " + s.substring(s.indexOf((pattern.charAt(pattern.indexOf('*')+1)))));
//return wildMatchRecursive(pattern.substring(pattern.indexOf('*')+1),s.substring(s.length()-(pattern.substring(pattern.indexOf('*')+1)).length()));
return wildMatchRecursive(pattern.substring(pattern.indexOf('*')+1),s.substring(s.indexOf((pattern.charAt(pattern.indexOf('*')+1)))));
}


return false;


}

- Eshwar April 16, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

static boolean wildMatchRecursive(String pattern, String s){

if((pattern.length()==1 && s.length()==1) && (pattern.charAt(0)==s.charAt(0) || pattern.charAt(0)=='?')){

return true;
}
       if(pattern.length()==1 && pattern.charAt(0)=='*'){

return true;
}
      if(pattern.length()==1 && pattern.charAt(0)=='?'){
   return false;
     }

if(pattern.length()==1 && s.length()==1){

return false;
}


if(pattern.charAt(0)==s.charAt(0) || pattern.charAt(0)=='?'){

return wildMatchRecursive(pattern.substring(1), s.substring(1));
}else if(pattern.charAt(0)=='*'){

System.out.println("$$  " + s.substring(s.indexOf((pattern.charAt(pattern.indexOf('*')+1)))));
//return wildMatchRecursive(pattern.substring(pattern.indexOf('*')+1),s.substring(s.length()-(pattern.substring(pattern.indexOf('*')+1)).length()));
return wildMatchRecursive(pattern.substring(pattern.indexOf('*')+1),s.substring(s.indexOf((pattern.charAt(pattern.indexOf('*')+1)))));
}


return false;


}

- Eshwar April 16, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

static boolean wildMatchRecursive(String pattern, String s){

if((pattern.length()==1 && s.length()==1) && (pattern.charAt(0)==s.charAt(0) || pattern.charAt(0)=='?')){

return true;
}
if(pattern.length()==1 && pattern.charAt(0)=='*'){

return true;
}
if(pattern.length()==1 && pattern.charAt(0)=='?'){
return false;
}

if(pattern.length()==1 && s.length()==1){

return false;
}


if(pattern.charAt(0)==s.charAt(0) || pattern.charAt(0)=='?'){

return wildMatchRecursive(pattern.substring(1), s.substring(1));
}else if(pattern.charAt(0)=='*'){

System.out.println("$$ " + s.substring(s.indexOf((pattern.charAt(pattern.indexOf('*')+1)))));
//return wildMatchRecursive(pattern.substring(pattern.indexOf('*')+1),s.substring(s.length()-(pattern.substring(pattern.indexOf('*')+1)).length()));
return wildMatchRecursive(pattern.substring(pattern.indexOf('*')+1),s.substring(s.indexOf((pattern.charAt(pattern.indexOf('*')+1)))));
}


return false;


}

- Anonymous April 16, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

static boolean wildMatchRecursive(String pattern, String s){

if((pattern.length()==1 && s.length()==1) && (pattern.charAt(0)==s.charAt(0) || pattern.charAt(0)=='?')){

return true;
}
if(pattern.length()==1 && pattern.charAt(0)=='*'){

return true;
}
if(pattern.length()==1 && pattern.charAt(0)=='?'){
return false;
}

if(pattern.length()==1 && s.length()==1){

return false;
}


if(pattern.charAt(0)==s.charAt(0) || pattern.charAt(0)=='?'){

return wildMatchRecursive(pattern.substring(1), s.substring(1));
}else if(pattern.charAt(0)=='*'){

System.out.println("$$ " + s.substring(s.indexOf((pattern.charAt(pattern.indexOf('*')+1)))));
//return wildMatchRecursive(pattern.substring(pattern.indexOf('*')+1),s.substring(s.length()-(pattern.substring(pattern.indexOf('*')+1)).length()));
return wildMatchRecursive(pattern.substring(pattern.indexOf('*')+1),s.substring(s.indexOf((pattern.charAt(pattern.indexOf('*')+1)))));
}


return false;


}

- Eshwar April 16, 2015 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More