## Adap.tv Interview Question for Developer Program Engineers

Country: United States

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

``````string str1 ;
string str2;
int l_1 = str1.length();
int l_2 = str2.length();

if (l_1 != l_2)
{
printf("false\n");
}
else
{
int i;
int flag = 0;
for(i = 0; i < l_1; i++)
{
if( str1[i] != str2[i])
{
flag = 0;
break;
}
else
{
flag = 1;
}
}
if ( flag == 0)
{
printf("false\n");
}
else
{
printf("yes\n");
}
}``````

Comment hidden because of low score. Click to expand.
0

Did you answer OP's question or just post your code as practice for yourself (selfishly) ?

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

If this is how the question was phrased, I would first clarify what is the goal of the comparison. Are we trying to find how similar/dis-similar, or just a simple true/false if they are exact or not? Also, is our comparison case-sensitive?

For this example I will use the following assumtions:

1. We want a true/false based on an exact match of the length/characters
2. Our comparison is indeed case sensitive (boo != Boo)

In my below example, I convert Java String to a character array so that the algorithm is applicable to other languages and not cluttered with Java's built-in String functions. Simply put, the algorithm for string comparison is:

1. Check for equal length, if not then return false.
2. Check sequentially through each array comparing 1 char at a time, if any are different then return false
3. If 1 and 2 both clear without returning false, then return true as they are the same.

``````public boolean compareStrings(String s1, String s2){
char[] first = s1.toArray();
char[] second = s2.toArray();

if(first.length != second.length){
return false;
}

for(int i = 0; i < first.length; i++){
if(first[i] != second[i]){
return false;
}
}

return true
}``````

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.

### 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.