Adobe Interview Question for Software Engineer / Developers






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

Reverse the string
Find the maximum substring

- DashDash July 06, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Wrong !!!!

abcdgdba

Reverse it : abcdgdba

"ab" matches , but it is not a palindromic substring .

- @ Above July 06, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Reverse of abcdgba = abgdcba
Max substring = dgd which is a palindrome

One step I missed here is after finding all the substring check for palidrome as well

- DashDash July 17, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

ABCdEEfCBA..
Does your solution works for this? EE is max palindrome.
I think your solution fails here.

- jobseeker November 13, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. traverse each character left to right.
2. compare character i to i+1 and i+2 (since palindromes can be odd or even)
3. in a loop, compare i-n with i+1+n in sequence until the chars don't match.
4. Keep track of maxLength and maxIndex.
5. Build in early exits and proper null checks.

public string FindLongestPalindrome(string item)
{
   if (item==null || item==string.empty) return string.empty;
   int maxLength = 1;
   int maxIndex = 0;

   for (int i=0; i < item.Length - maxLength /*earlyExit*/; i++)
   {
      for (int j=1; j < 3; j++)
      {  
          if (i+j >= item.length) break;
          if (item[i] != item[i+j]) continue;
          int start=i;
          int end = i+j;
          while (start > 0 && end < item.length - 1)
          {
              if (item[start-1] != item[end+1]) break;
              start--;
              end++;
          }
          if (end-start > maxLength)
          { 
             maxIndex = start;
             maxLength = end-start;
          }
   }
   return item.SubString(maxIndex, maxLength);
}

- SomeGuy July 06, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

array index out of bound exception in first if stmnt of while loop.
The algo fails for first case when start = i =0

- Anonymous July 07, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I didn't understand whats wrong with reversing of a string, since we are getting ab which is the actually longest palindrome ab***ba abba..?? correct me if i m wrong..

- Anish July 07, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

"ab" is a palindrome ???????????

- Anonymous July 07, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Ibnipun is correct. But has to be improved.

1. Find the LCString of A and reverse of A.
2. You get say string B.
3. If B is a palindrome, only then does A have a palindrome (i.e of length atleast two, well, every letter is a palindrome of itself :) ). Otherwise no palindrome.

- VINOD July 08, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Ibnipun is correct.

1. Find the LCString of A and reverse of A.
2. You get say string B.
3. If B is a palindrome, only then does A have a palindrome (i.e of length atleast two, well, every letter is a palindrome of itself :) ). Otherwise no palindrome.

- VINOD July 08, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Let S is given string, T is reverse of S. Build a generalized suffix tree GST (see Wikipedia) for S and T. Search for the longest common prefix in GST.
example: S = 1232, T = 2321
suffixes of S = {1232,232,32,2}, and of T = {2321,321,21,1}
"232" is the longest common prefix. Even though number of possible suffixes in GST can be O(n^2), it can be collapsed to represent in compact way. As compact GST can be be built in O(n) time with O(n) space, it's probably optimal solution (surely, not easy to code with space/time constraint).

Plz correct if I'm wrong.

- buried.shopno July 10, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

yea thats the rt answer!

- newbie July 30, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

here is some pseudocode
i hope it solves the problem
as i see it is a DP problem
I have given a recursive solution , memoisation will give O(N^2) time complexity


int palindrome(char str[],int start,int end,int len)
{ if(len==1) return 1;

else if((str[start]==str[end]) && palindrome(str,start+1,end-1,len-1))
return 1;
else return 0;


}
struct start_end longest_palindrome(char str[],int start,int end,int len)
{ if(palindrome(str,start,end,len)
return start,end
else
{

}

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

here is some pseudocode
i hope it solves the problem
as i see it is a DP problem
I have given a recursive solution , memoisation will give O(N^2) time complexity


int palindrome(char str[],int start,int end,int len)
{ if(len==1) return 1;

else if((str[start]==str[end]) && palindrome(str,start+1,end-1,len-1))
return 1;
else return 0;


}
struct start_end longest_palindrome(char str[],int start,int end,int len)
{ if(palindrome(str,start,end,len)
return start,end
else
{ ret=longest_palindrome(str,start+1,end,len-1);
if(ret!=NULL)
return ret;
else
{ ret=longest_palindrome(str,start+1,end,len-1);
if(ret!=NULL)
return ret;
}
}
return NULL;
}

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

here is some pseudocode
i hope it solves the problem
as i see it is a DP problem
I have given a recursive solution , memoisation will give O(N^2) time complexity


int palindrome(char str[],int start,int end,int len)
{ if(len==1) return 1;

else if((str[start]==str[end]) && palindrome(str,start+1,end-1,len-1))
return 1;
else return 0;


}
struct start_end longest_palindrome(char str[],int start,int end,int len)
{ if(palindrome(str,start,end,len)
return start,end
else
{ ret=longest_palindrome(str,start+1,end,len-1);
if(ret!=NULL)
return ret;
else
{ ret=longest_palindrome(str,start+1,end,len-1);
if(ret!=NULL)
return ret;
}
}
return NULL;
}
I hope this is understandable . bOTH functions need to be memoized..
Please correct me ,if i am wrong

- ravikant July 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

sry correction
in the longest palindrome fucntion
the second recursive call should be
ret=longest_palindrome(str,start,end-1,len-1);

- Anonymous July 24, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is modification done over the previous concept. This works fine.

struct start_end{
int s;
int e;
};
int palindrome(char str[],int start,int end,int len)
{
if(len==1 || start>end) return 1;
else if((str[start]==str[end]) && palindrome(str,start+1,end-1,len-2)) return 1;
else return 0;
}

struct start_end longest_palindrome(char str[],int start,int end,int len)
{
start_end ret1={0,0},ret2={0,0};
static start_end tvar={0,0};
if(len>1)
if(palindrome(str,start,end,len)){start_end temp;temp.s=start;temp.e=end;return temp;}
else
{
ret1=longest_palindrome(str,start+1,end,len-1);
ret2=longest_palindrome(str,start,end-1,len-1);
if(ret1.e-ret1.s>ret2.e-ret2.s)
tvar=ret1;
else tvar=ret2;
}
return tvar;
}

- vivek BIT Mesra February 04, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

var pal = ['a','b','c','d','c','b','a'];
var reversePal = pal.reverse();
var count = 0;

for( i=0; i < pal.length; i++ )
{
	var newPal = pal.slice(0,i);
	var newReversePal = reversePal.slice(0,i);
	alert( newPal + " : " + newReversePal );
	if( newPal.toString() == newReversePal.toString() )
	{
		count = i;	
	}
}

alert( count);

- Anonymous November 29, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

a O(n^2) solution

int palindrome(int a[], int n)
{
    int LongestSoFar = 0, start, end, count=0,lstart,lend;
    for(int i=0;i<n;i++)
    {
        if(count>LongestSoFar)
        {
            LongestSoFar = count;
            lstart = start;
            lend = end;
        }
        count = 0;
        for(int p = i,q=i;p>=0&&q<n;p--,q++)
        {
            if(a[p]!=a[q])
                break;
            else
            {
                count++;
                start = p;
                end =  q;
            }
        }
    }
    for(i=lstart;l<=end;l++)
        count<<a[i];
    retun count;
}

- fabregas March 12, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

string largestPal(string input_str)
{
  string isPal = "";
  string largest = "";
  int j, k;
  for(int i = 0; i < input_str.length() - 1; ++i)
    {
      k = i + 1;
      j = i - 1;

      // starting a new interation                                                      
      // check to see if even pal                                                       
      if(j >= 0 && k < input_str.length()) {
        if(input_str[i] == input_str[j])
          j--;
        else if(input_str[i] == input_str[j]) {
          k++;
        }
      }
      while(j >= 0 && k < input_str.length())
        {
          if(input_str[j] != input_str[k])
            break;
          else
            {
              j--;
              k++;
            }
          isPal = input_str.substr(j + 1, k - j - 1);
            if(isPal.length() > largest.length()) {
              largest = isPal;
            }
        }
    }
  return largest;
}

- Nitin Gupta August 30, 2012 | 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