## Interview Question

Country: United States

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

Your final solution looks good to me. You could place some of the work with built in functions

My solution in C++ (you can replace isalpha with Character.isLetter(char) and tolower with Character.toLowerCase(char) in java if you like))

``````bool isPal(const char* str)
{
int f=0;
int b=strlen(str)-1;
while(f>b)
{
char front=tolower(str[f]); //normalize for upper vs lower comp
while(!isalpha(front) && f>b) 	//skip non alpha chars
front=tolower(str[++f]);

char back=tolower(str[b]); //normalize for upper vs lower comp
while(!isalpha(back) && f>b)	//skip non alpha chars
back=tolower(str[--b]);

if(front!=back)
return false;

}

return true;
}``````

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

all those f>b comparisons should be f<b...you win some you lose some ;-)

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

``````public class Palindrome {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

String str1="1sunilinus";

if (str1.matches(".*[^a-zA-Z].*\$") == true ){
System.out.println("Not a valid string");
return;
}

System.out.println("Is it Palindrome : "+isPalindrome(str1));

}

public static boolean isPalindrome(String s){
char[] str = s.toCharArray();
int len=str.length;

System.out.println("Length of String: "+len);

//loop
int start = 0;
int end = len-1;

while(start<end)
{
if(str[start++] != str[end--])
return(false);
}

return(true);
}

}``````

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

Solution in C# (Case and analphabetic charachters are ignored)

``````public static bool WordCheck(string word)
{
word = word.ToLower();
string reversedWord = string.Empty;
for (int i = word.Length - 1; i >= 0; i--)
{
if (Convert.ToInt32(word[i]) > 96 && Convert.ToInt32(word[i]) < 123)
reversedWord += word[i];
}
return reversedWord == word ? true : false;
}``````

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

Solution in JavaScript:

``````var palindromeCheck = function(string) {

var len = string.length - 1;
var alpha = /^[a-zA-Z]+\$/;

for ( var i = 0, k = len; i < k; i++, k-- ) {
while ( !alpha.test(string[i]) ) { i++; }
while ( !alpha.test(string[k]) ) { k--; }
if ( string[i] !== string[k] ) { 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.