Amazon 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

1. get to middle element of string.
2. take two pointers p1 and p2 point to middle element(if string is of odd length, or two different middle elements incase of even length).
3. while (p1 >= start, p2 <= end)
{
if (*p1 !=*p2)
return FALSE;
p1--;
p2++;
}
return true;

- Punit Jain April 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Code:
int len = strlen( str );
for(int i = 0; i< len; i++)
{
if(a[i] != a[len-1-i])
flag = 1;
}

if( flag )
Not a palindrome
else
A palindrome.

Complexity:
O(n)

- Pavan Dittakavi May 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package com.palindrometest;

public class PalindromeDate {

public static void main(String[] args) {

String input = "ISUDUSR";
boolean isPalindrome = false;
int i = 0;
int j = input.length()-1;
while(i <= input.length()/2 && j>=input.length()/2+1) {
if(input.charAt(i++) == input.charAt(j--)) {
isPalindrome = true;
} else {
isPalindrome = false;
}

}
if(isPalindrome) {
System.out.println("Palindrome");
} else {
isPalindrome = false;
System.out.println("Not a Palindrome");
}
}
}

- Sumanta Mukherjee April 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class palindrome
{
public static void main(String args[])
{
String data="abcdcba";
int length=data.length()-1;
int i=0;
while(data.charAt(i)==data.charAt(length)&&i++<length--);
if(i>=length)
System.out.println("True");
else
System.out.println("false");
}
}

- sharma April 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool isPalindrome(string str)
{
for (int i = 0; i < str.size()/2; i++) {
if (str[i] != str[str.size()-i-1]) {
return false;
}
}
return true;
}

- Anonymous April 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public boolean isPalindrome(String str){
	return str.equals(new StringBuilder(str).reverse().toString()); 		
}

- Praveen April 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I dont think u will be allowed to use inbuilt functions

- Anonymous April 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool Ispalindrome(string s)
{
	int i = s.size()/2 + 1;
	int j = s.size()/2 + 1;
	if (s.size()%2 == 0)
	{
		i--;
	}
	while ( i >= 0)
	{
		if (s[i]!=s[j])
			return false;
		i--;
		j++;
	}
	return true;
}

- gbhati May 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

boolean isPalindrome(String str){
        if(str==null) return false;
        int length=str.length();
        int start=0;
        int end=length-1;
        str=str.toLowerCase();
        
        while(start<end){
            if(str.charAt(start)==' ') start++;
            if(str.charAt(end)==' ') end--;
            if(str.charAt(start)!=str.charAt(end)){
               return false;
            }
            start++;
            end--;
        }
        return true;

}

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

Can we XOR the ascii values of the entire string ?

- abhishek376 May 12, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Approach would be right if string length is even. It wouldn't work for string which is of odd length.

- Punit Jain May 12, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

{
{
{

for(i = 0 , j = strlen(str-1) ; i < j && str[i] == str[j] ; ++i , --j);
if(i >=j )
puts("palndrome hai yaar");

}
}
}

- Luv singh July 23, 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