Goldman Sachs Interview Question for Software Engineer / Developers






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

bool isPalindrom(const char * str)
{
   int i = 0, j = strlen(str) - 1;
   while (i < j) if (str[i++] != str[j--]) return false;
   return true;
}

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

reverse the string, then compare with the original string.

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

int isPalindrome(char *str) {
   char * end = strlen(str) - 1;
   while (str < end) {
      if (*str != *end) return -1;
   }
   return 1;
}

- Anonymous August 16, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Won't run..
worst solution...
make sure where end is pointing .. u r not incrementing start and not decrementing j

- Anonymous December 04, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

C# Code

private bool IsPalindrome(string inputString)
{
bool isPalindrome = false;
if (new string(inputString.Reverse<char>().ToList<char>().ToArray<char>()).Equals(inputString))
{
isPalindrome = true;
}
return isPalindrome;
}

- anci September 23, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static boolean isPalindrome(String name){
		boolean isPalindrome = true;
		int j = name.length()-1;
		for(int i = 0; i< j; i++,j--){
			if(name.charAt(i)!= name.charAt(j)){
                	isPalindrome = false;
                    break ;
                }
		}
		return isPalindrome;
	}

- Nikhil September 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Why everybody is iterating through whole String. You have to traverse 1/2 string. Start from both the side.

boolean isPalindrom=true;

for(int i=0;i<str.length()/2;i++)
{
if(str.charAt(i)!=str.charAt(str.length()-1-i))
isPalindrom=false;
}

- Piyush November 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@piyush
dude everyone is decrementing j in their loop ...

- Anonymous December 04, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool palindrome( string s)
{
    string::iterator p1 = s.begin();
    string::iterator p2 = s.end();
    p2--;
    while ((*p1==*p2) && (p1<p2))
    {
        cout << "testing " << *p1 << *p2  << endl;
        p1++;
        p2--;
    }
    return (p1>=p2);
}

- jcarrion February 15, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Java CODE:


import javax.swing.JOptionPane;
public class CheckPalindrome
{
public static void main(String[] args)
{
String s=JOptionPane.showInputDialog(null,"Enter a string ","Example",JOptionPane.QUESTION_MESSAGE);
String output="";
if(isPalindrome(s))
{
output=s+" is a palindrome!";
}
else
output=s+" is not a palindrome!";
JOptionPane.showMessageDialog(null,output,"The result",JOptionPane.INFORMATION_MESSAGE);
}
public static boolean isPalindrome(String s)
{
int low=0;
int high=s.length()-1;
while(low<high)
{
if(s.charAt(low)!=s.charAt(high))
return false;
low++;
high--;
}
return true;
}

}

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

bool isPalindrom(const string &s) {
    for(string<char>::const_iterator iter = s.begin(); iter <= s.size()/2; ++iter)
    {
        if( *iter != *(iter+(s.size()-(iter-s.begin()))) return false;
    }
    return true;
}
Complexity O(N/2)

- Anonymous March 02, 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