Adobe Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

Do the same functionality as palindrome function does with below modifications:
a) you can convert the string to all lowercase
b) consider only ASCII characters within range 97-122 (a-z)

- arsragavan March 19, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yes.. almost that's (ASCII) what I did, but i did not convert the string to lowercase... Below is a working solution:

class Palindrome
    {
        static void Main(string[] args)
        {
            string[] strs = new string[]{"Madam, I'm Adam!", "Bob", "", "   ", "fuluf", "full"};
            foreach (string str in strs)
            {
               try
                {
                    if (IsPalindrome(str))
                    {
                        System.Console.WriteLine(str + " IS a palindrome");
                    }
                    else
                    {
                        System.Console.WriteLine(str + " is NOT a palindrome");
                    }
                }
                catch (Exception e)
                {
                    System.Console.WriteLine("Exception caught: " + e);
                }
            }
        }

 public string splcharfreestring(string str)
    {
      char[] ca = str.ToCharArray();
      StringBuilder sb = new StringBuilder();
      int i=0;
      for (i=0; i< str.Length; i++)
        {
         if((ca[i] >= 'A' && ca[i] <= 'Z') || (ca[i] >='a' && ca[i] <= 'z'))
          {
           sb.Append(ca[i]);
          } 
        
         else
           continue;
        }
        
       return sb.ToString();
  
     }

        static bool IsPalindrome(string str)
        {
            Palindrome sl = new Palindrome();

            string elimatesplchars;
            elimatesplchars = sl.splcharfreestring(str);
            bool ispal = false;
            char[] ca = elimatesplchars.ToCharArray();
            int i = 0, j = elimatesplchars.Length - 1;

            if (str == null)
            {
                throw new Exception("str is null");
            
            }
            
            if (str.Length == 1)
                return true;

            else if (str == "")
                return false;
            else
            {
                for (i = 0; i < ca.Length / 2; i++)
                {
                    char ch = ca[j];
                    if ((ca[i] == ca[j]) || (ca[i] == (char) (ch + 32) || (ca[i] == (char) (ch - 32)) ))
                    {
                        ispal = true;
                        j--;
                        continue;
                    }
                    else
                    {
                        ispal = false;
                        return ispal;

                    }

                }

            }
            if (ispal == true)
                return ispal;


            return ispal;
        }
}

- Jeanclaude March 19, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

Too easy to be an interview question!

- Le Subbu March 19, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int check_paldm(char *str){

char *p,*ptr;
ptr=str;
int len;
len=strlen(str);
p=ptr+len-1;

while(*ptr!='\0'){

if(*p>=97)
*p=*p-32;

if(*ptr>=97)
*ptr=*ptr-32;

if(*ptr>91 || *ptr<65){

ptr++;
continue;
}

if(*p>91 || *p<65){

p--;
continue;
}

if(*p==*ptr){

printf("p = %c and ptr = %c\n",*p,*ptr);
p--;
ptr++;
continue;
}else{

return FALSE;
}
}
return TRUE;
}

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

use strict;
use warnings;

print "a = ";
my $a = lc <STDIN>;
chomp $a;
my @a_arr = split //, $a;
@a_arr = grep { /[\w]/ } @a_arr;
my $bool = 1;

while(@a_arr)
{
    my $f = $a_arr[0];
    my $l = pop @a_arr;
    if($f ne $l)
    {
        print "false\n";
        $bool = 0;
        last;
    }
    shift @a_arr;    
}

print "true\n" if($bool);

- Here's Perl March 29, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Check this out..
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *trim(char *);
int main()
{
char str[80],*beg,*end,*str1;
int i=0,flag=0,x;
printf("Enter the string:");
gets(str);
//preprocess string remove any special char.
str1=trim(str);

strcpy(str,str1);

beg=str;
end=str+strlen(str)-1;
x=strlen(str)/2;
while(i!=x&&x>0)
{

if((*beg++)!=(*end--))
{
flag=1;
printf("\nNot palindrome");
break;
}
i++;

}
if(flag==0)
printf("\nPalindrome");
return 0;
}
char *trim(char *str)
{
char temp[strlen(str)],*str1;
int count=0,k=0,j=0;
while(*str!='\0')
{
if(((*str>='a'&&*str<='z')||(*str>='A'&&*str<='Z')))
{
temp[count++]=*str;
}
str++;

}
str1=malloc(strlen(temp)*sizeof(char*));
strcpy(str1,temp);

return str1;

}

- Shirsh Sinha April 05, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>
#include <algorithm>
using namespace std;

bool palin(string str)
{
    transform(str.begin(),str.end(),str.begin(),::tolower); //Convert to lower case
    int len = str.length();
    int mid = (len)/2;
    for(int i=0;i<=len-1;i++)
    {
        if(str[i]<97 || str[i]>122 || str[len-i-1]<97 || str[len-i-1]>122)
        {
            continue;
        }
        if(str[i]!=str[len-i-1])
        {
            return false;
        }
    }
    return true;
}

int main()
{
    string str = "Madam i'm Adam";
    if(palin(str))
    {
        cout << "Palindrome" << endl;
    }
    else
    {
        cout << "NOT palindrome" << endl;
    }
}

- Gudi Boss May 04, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Took out the "mid" from my previous post.

#include <iostream>
#include <algorithm>
using namespace std;

bool palin(string str)
{
    transform(str.begin(),str.end(),str.begin(),::tolower); //Convert to lower case
    int len = str.length();
    for(int i=0;i<=len-1;i++)
    {
        if(str[i]<97 || str[i]>122 || str[len-i-1]<97 || str[len-i-1]>122)
        {
            continue;
        }
        if(str[i]!=str[len-i-1])
        {
            return false;
        }
    }
    return true;
}

int main()
{
    string str = "Madam i'm Adam";
    if(palin(str))
    {
        cout << "Palindrome" << endl;
    }
    else
    {
        cout << "NOT palindrome" << endl;
    }
}

- Gudi Boss. May 04, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class abc {

public boolean palindrom(String str)
{
str=str.toLowerCase();
str=removeSpecialChar(str);
return new StringBuffer(str).reverse().toString().equals(str)?true:false;
}
public String removeSpecialChar(String str){

String s="";
for(int i=0;i<str.length();i++)
{
if(str.charAt(i)>='a' && str.charAt(i)<='z')
{
s=s+str.charAt(i);
}
}
return s.trim();

}
public static void main(String[] args) {

System.out.println(new abc().palindrom("Madam, I'm Adam!!"));

}
}

- Anand Kumar Tiwari May 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<string.h>
#include <ctype.h>
bool checkPalindrome(char *seq){
    int n = strlen(seq);
    int left=0,right=n-1;
    
    while(left<right){
                      
        
        while(((seq[left]<'A' || seq[left]>'Z') && !(seq[left]>'a' && seq[left]<'z'))==true)  
        left++;            
        while(((seq[left]<'a' || seq[left]>'z') && !(seq[left]>'A' && seq[left]<'Z')) ==true)
        left++;
        while(((seq[right]<'A' || seq[right]>'Z') && !(seq[right]>'a' && seq[right]<'z'))==true)  
        right--;            
        while(((seq[right]<'a' || seq[right]>'z') && !(seq[right]>'A' && seq[right]<'Z')) ==true)
        right--;
        
        if(tolower(seq[left])==tolower(seq[right]))
        {
          left++;
          right--;                         
        }
        else
        return false;
        }            
       return true;     
    }
    
int main(){
    char str[]="Madam, I'm Adam!";
    
    if(checkPalindrome(str))
    printf("Palindrome");
    else
    printf("Not a Palindrome");
    getchar();
    return 0;

}

- Anonymous May 14, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public bool IsPalindrom(string input)
        {
            if (string.IsNullOrWhiteSpace(input))
            {
                return false;
            }

            int startIndex = 0, endIndex = input.Length - 1;
            while (startIndex <= endIndex)
            {
                while (!IsAnAlphabet(input[startIndex]) && startIndex < endIndex)
                {
                    startIndex++;
                }

                while (!IsAnAlphabet(input[endIndex]) && startIndex < endIndex)
                {
                    endIndex--;
                }

                int diff =  input[startIndex] - input[endIndex];
                if (!(diff == 0 || diff == 32 || diff == -32))
                {
                    return false;
                }

                startIndex++;
                endIndex--;
            }

            return true;
        }

        public bool IsAnAlphabet(char c)
        {
            return (65 <= c && c <= 90 || (97 <= c && c <= 122));
        }

Only case won`t be handled is when string is all special case say "!!@#!@$@#$@#$", if will true rather than false.

- tiwaripradeep123 June 07, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
main(){
       char a[100];
       int length,i,j,index=0;
       char *p;
       gets(a);
       length=strlen(a);
       p=(char *)malloc(sizeof(char));
       
       for(i=0;i <length; i++){
                 
                 if( isalpha(a[i])|| isdigit(a[i])){
                     p[index]=isupper(a[i])? tolower(a[i]): a[i];
                     index++;
                     }
                     }
       for(i=0; i <index ;i++) printf("%c",p[i]);
      // printf("\nindex=%d \n",index);
       for(i =0, j=index-1; i <= j; i++,j--){
         
             if( p[i]== p[j]) continue;
             else {
                  printf("\nstring %s is not palindrom\n",a);
                  break;
                  }
                  }
      
      if(i-1==j+1) printf("\nstring %s is palindrome\n",a);
       scanf("%d",&i);
                  }

- sumit June 16, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Palindrome {

	private boolean isPalindrom(String s) {
		if(s.trim().length()==0){
			return false;
		}
		
		int i = 0;
		int j = s.length() - 1;

		while (i < j) {

			if (s.toLowerCase().charAt(i) == s.toLowerCase().charAt(j)) {
				i++;
				j--;

				while (s.toLowerCase().charAt(i) < 'a'
						|| s.toLowerCase().charAt(i) > 'z') {
					i++;
				}

				while (s.toLowerCase().charAt(j) < 'a'
						|| s.toLowerCase().charAt(j) > 'z') {
					j--;
				}

			} else {
				return false;
			}

		}

		return true;
	}

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

public class Palindrome {

	private boolean isPalindrom(String s) {
		if(s.trim().length()==0){
			return false;
		}
		
		int i = 0;
		int j = s.length() - 1;

		while (i < j) {

			if (s.toLowerCase().charAt(i) == s.toLowerCase().charAt(j)) {
				i++;
				j--;

				while (s.toLowerCase().charAt(i) < 'a'
						|| s.toLowerCase().charAt(i) > 'z') {
					i++;
				}

				while (s.toLowerCase().charAt(j) < 'a'
						|| s.toLowerCase().charAt(j) > 'z') {
					j--;
				}

			} else {
				return false;
			}

		}

		return true;
	}

- MAHI July 03, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool check = true;
bool isPalindrome(string str, int start, int end)
{
    if(start<end)
    {
        while(start<=end && !((str[start] >= 'a' && str[start] <= 'z') || (str[start] >= 'A' && str[start] <= 'Z')))
            start++;
        while(end >=0 && !((str[end] >= 'a' && str[end] <= 'z') || (str[end] >= 'A' && str[end] <= 'Z')))
            end--;
        if(toupper(str[start]) != toupper(str[end]))
        {
            check = false;
            return false;
        }
        return check && isPalindrome(str, start+1, end-1);
    }
    return true;
}

- skum July 29, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#include <string.h>

//method should ignore special characters and white spaces
//method should consider lower case and upper case characters to be the same

int check_palindrome(const char *user_str)
{
int i, j;

const int len = strlen(user_str);

char check_str[len];

for(i=len-1, j=0; i>=0; i--, j++)
{
check_str[j] = user_str[i];
}
check_str[j] = '\0';

if( strcmp(user_str, check_str) == 0 )
return 1;
else
return 0;
}

static void prepare_string_for_process2(char *str) //Without using a temporary buffer
{
int i, j;

for(i=0, j = 0; i<strlen(str); i++)
{
if( isalpha(str[i]) )
{
if( isupper(str[i]) )
{
str[j++] = tolower(str[i]);
}
else
str[j++] = str[i];
}
else
{
if( !isdigit(str[i]) )
continue;
else
str[j++] = str[i];
}
}
str[j] = '\0';

printf("\n Modified string is (without temp buffer): %s", str);

}

static void prepare_string_for_process1(char *str) //using a temporary buffer
{
int i, j;
const int len = strlen(str);

char processed_str[len];

for(i=0, j=0; i<len; i++)
{
if( isalpha(str[i]) )
{
if( isupper(str[i]) )
processed_str[j++] = tolower(str[i]);
else
processed_str[j++] = str[i];
}
else if( isdigit(str[i]) )
{
processed_str[j++] = str[i];
}
}
processed_str[j] = '\0';

strcpy(str, processed_str);

printf("\n Modified string is (with temp buffer): %s", processed_str);
}

int main()
{
char str[50];
int n;

printf("\n Please enter a string (Please ensure that the string doesn't exceed 49 characters):");
fgets(str, sizeof(str), stdin);

n = strlen(str)-1;
if( str[n] == '\n' )
str[n] = '\0';

//prepare_string_for_process1(str); //With temporary buffer

prepare_string_for_process2(str); //Without temporary buffer

if( check_palindrome(str) == 1 )
printf("\n The string \'%s\' is a palindrome \n", str);

return 0;
}

- Anuhya September 07, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

a = raw_input("enter the string")
    c = filter(a.isalpha, a)
    c = c.lower
    rev_c = c[::-1]
    if c == rev_c:
        print "Palindrome"
    else:
        print "Not a palindrome"

- Ridhibhan.19 August 12, 2016 | 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