Amazon Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




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

bool isPalindrome(char* s){
int l = strlen(s);
for(int i=0;i<(l/2); i++)
if (s[i] != s[l-(i+1)])
return false;
return true;
}

- Champ Coda October 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

typedef enum {false, true} bool;

bool isPalindrome(char*str, size_t nStartIndex, size_t nEndIndex)
{
if (nStartIndex > nEndIndex) return false;
else if (nStartIndex == nEndIndex) return true;
else if (str[nStartIndex] == str[nEndIndex])
{
if (nEndIndex - nStartIndex == 1) return true;
else return isPalindrome(str, nStartIndex + 1, nEndIndex - 1);
}
else return false;
}

This is untested code and is solely my crack at the problem. The call from the caller has to be made as:
isPalindrome(str, 0, n); where n is the last valid index of the string. Please let me know if it is ok.

- rookie October 08, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

correct

- anonymous October 09, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

might need to only consider letters of the alphabet, disregard punctuation or spaces (like in the example)

- dc October 10, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Amm if i declare a new pointer ... does it count as creating a "buffer"

heres my sol :

#include <stdio.h>

int main(int argc , char* argv[]){

	//take argv[1] ...
	char* temp = argv[1];
	while(*argv[1] != '\0')
		argv[1]++;

	argv[1]--;
	while(*temp != '\0'){
		if(*temp != *argv[1]){
			printf("%c %c no!\n",*temp,*argv[1]);
			return 1;
		}
		temp++;
		argv[1]--;
	}
	printf("yes!\n");
	return 0;
		
}

- lyfzabrutalcode October 10, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<string.h>

int main()
{
    char a[]="..A,,BC..DE.D.,C..BA...";
 int i=0;
 int j=strlen(a)-1;
 
 int flag=0;
 
 while(i<=j)
 {
            while(!(a[i]>='A' && a[i]<='Z'))
            {
                              printf("I String %c\n",a[i]);
                              
                              i++;
                              if(i>j)
                              {
                                     flag=-1;
                                     break;
                              }
            }
            if(flag==-1)
            {
                        printf("Not a palindrome\n");
                                              break;
 
            }
            else
            {
                
            while(!(a[j]>='A' && a[j]<='Z'))
            {
                              printf("J String %c\n",a[j]);
                              j--;
                              if(j<i)
                              {
                                     flag=-1;
                                     break;
                              }
            }
            if(flag==-1)
            {
                        printf("Not a palindrome\n");
                                              break;
 
            }
                
            
            }
            if(flag==0 && a[i]==a[j])
            {
                       i++;
                       j--;
                       
                       
            }
            else
            if(flag==0 && a[i]!=a[j])
            {
                       flag=-1;
                       printf("Not a palindrome\n");
                       break;
            }

 }
    if(flag==0)
    {
               printf("Palindrome\n");
               }
 
 system("PAUSE");   
}

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

public class start {

public static void main(String[] args) {

String s = "ABXBAZ";

int forward_i = 0;
int backward_i = s.length() - 1;

int ispalindrome = 1;

while(forward_i < backward_i)
{
if(s.charAt(forward_i) != s.charAt(backward_i))
{
ispalindrome = -1;
break;
}

forward_i++;
backward_i--;
}

System.out.println(ispalindrome);
}

}

- Murat October 16, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class start {

public static void main(String[] args) {

String s = "ABXBAZ";

int forward_i = 0;
int backward_i = s.length() - 1;

int ispalindrome = 1;

while(forward_i < backward_i)
{
if(s.charAt(forward_i) != s.charAt(backward_i))
{
ispalindrome = -1;
break;
}

forward_i++;
backward_i--;
}

System.out.println(ispalindrome);
}

}

- Murat Karakus October 16, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int palindrome(char a[]){
int l,i=0,count;
l=length(a);
l=l-1;
for(i=0;i<l;i++,l--){
if(a[i]==a[l]){
continue;
}
else
return 0;
}
return 1;
}

- Sreenath S Kamath August 07, 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