Synopsys R&D Interview Question for Senior Software Development Engineers


Country: India




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

int check (char[] s1 , char[] s2) { 	
	int i,j,s,ss;
	char cur_char;
	s1 = strlen(s1);
	ss = strlen(s2);
	cur_char = s1[0];	i=0;
	for(j=0;j<ss;++j) {
		if ( s2[j] == cur_char) {
			++i;
			cur_char = s[i]
		}
	}
	if ( i == s) return 1;
	return 0;
}

- Anonymous June 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

If I'm not wrong there is a typo?

s1 = strlen(s1);

should be

s = strlen(s1);

- Diwakar October 18, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Ex: String2 = "ABC"; String1="AXBYCZ". Answer = true;

Simple Algo:
First look for 1st char, then 2nd char in remaining string and so on..

boolean f(String str1, String str2)
{
	int begIndex = 0;
	for(int i=0; i<str2.length; ++i){
		int pos = str1.indexOf(str2.charAt(i), begIndex);
		if(pos == -1)	return false;
		begIndex = pos+1;
	}

	return true;
}

Need more details in problem def, for more sophisticated solution.

- X June 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think your interpretation of the problem makes more sense than the other ones. One tiny issue, I think it should be "begIndex = pos+1" so that if String2 = "ABCC" then Answer = false.

- Sunny June 22, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

yes, Sunny you are right.

- Sharma June 24, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Corrected, according to Sunny's comment. thx..

- X June 24, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

1.) Put all characters string2 in a stack.
2.) Then start traversing string1 in reverse order
2.1) If currect character matches with top of stack then pop it from stack.
3.) After traversing string1 fully, If stack is empty then return true else return false

- Nitin Gupta June 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Why use extra stack space and put all the chars of string2 on to it? Why traverse from the end of string1? Why this additional complexity? Is it in anyway more efficient than starting from the beginning of both the strings and comparing them character by character?

- Murali Mohan June 22, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

this is not working in the case of S1:abcd S2:ebfd

- ashwitha93 June 23, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

just traverse the strings character by character

- lilian June 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here's my idea in Python:

# Using the test case provided above
	s1 = 'AXBYCZ'
	s2 = 'ABC'
	
	common_str = [c for c in s2 if c in s1]  # Filter out unwanted chars
	common_str2 = [c for c in s1 if c in common_str] 
        
	return common_str == common_str2

- OranjePrv91 March 31, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

for(i=0,j=0;j<strlen(str1)&&i<strlen(str2);i++)
{
if(str2[i]==str1[j])
j++;
}
if(j==strlen(str1))
printf("\n Found the code");
else
printf("\nsorry!");

- Preeti July 24, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

for(i=0,j=0;j<strlen(str1)&&i<strlen(str2);i++)
    {
        if(str2[i]==str1[j])
            j++;
    }
    if(j==strlen(str1))
        printf("\n Found the code");
    else
        printf("\nsorry!");

- Preeti July 24, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

Compare the two strings character by character

- Murali Mohan June 22, 2013 | 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