Goldman Sachs Interview Question for Developer Program Engineers


Country: India
Interview Type: Written Test




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

import java.util.*;
import java.lang.*;
import java.io.*;


class topalindrome
{
	public static void main (String[] args) throws java.lang.Exception
	{
	    String str = "hcasach";
		palindrome(str);
	}
	
	public static void palindrome(String str)
	{
	  int len =   str.length();
	   for(int l=0,r=len-1;l<=r;l++,r--)
	   {
	       if(str.charAt(l)!=str.charAt(r))
	       {
	      char insert = str.charAt(r);
	      if(l==0){
	      str = insert + str;
	      r=r+1;
	      }
	      else
	      {
	     String str1 = str.substring(0,l);
	     String str2 = str.substring(l);
	      str = str1 + insert + str2;
	     r=r+1;
	      }
	      
	       }
	   }
System.out.println(str);
	}	
}

- kanika April 25, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

what is the necessity of else part please explain?

- sangeethkumar1157 May 28, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class formShortestPalindrome {
public static void main(String [] args){
System.out.println(formPalin("java"));
}

static String formPalin(String s){
if(s == "" || s.length() == 1)
return s;
char firstChar = s.charAt(0);
char lastChar = s.charAt(s.length() - 1);
if(firstChar == lastChar) {
if(s.length() != 2)
return firstChar + formPalin(s.substring(1, s.length() - 1)) + lastChar;
else
return s;
}
else {
return lastChar + formPalin(s.substring(0, s.length() - 1)) + lastChar;
}

}
}

- modernphysics June 08, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class formShortestPalindrome {
    public static void main(String [] args){
        System.out.println(formPalin("java"));
    }

    static String formPalin(String s){
        if(s == "" || s.length() == 1)
            return s;
        char firstChar =  s.charAt(0);
        char lastChar  =  s.charAt(s.length() - 1);
        if(firstChar == lastChar) {
            if(s.length() != 2)
                return firstChar + formPalin(s.substring(1, s.length() - 1)) + lastChar;
            else
                return s;
        }
        else {
            return lastChar + formPalin(s.substring(0, s.length() - 1)) + lastChar;
        }

    }
}

- modernphysics June 08, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class formShortestPalindrome {
    public static void main(String [] args){
        System.out.println(formPalin("java"));
    }

    static String formPalin(String s){
        if(s == "" || s.length() == 1)
            return s;
        char firstChar =  s.charAt(0);
        char lastChar  =  s.charAt(s.length() - 1);
        if(firstChar == lastChar) {
            if(s.length() != 2)
                return firstChar + formPalin(s.substring(1, s.length() - 1)) + lastChar;
            else
                return s;
        }
        else {
            return lastChar + formPalin(s.substring(0, s.length() - 1)) + lastChar;
        }

    }

}

- Anonymous June 08, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class formShortestPalindrome {
public static void main(String [] args){
System.out.println(formPalin("java"));
}

static String formPalin(String s){
if(s == "" || s.length() == 1)
return s;
char firstChar = s.charAt(0);
char lastChar = s.charAt(s.length() - 1);
if(firstChar == lastChar) {
if(s.length() != 2)
return firstChar + formPalin(s.substring(1, s.length() - 1)) + lastChar;
else
return s;
}
else {
return lastChar + formPalin(s.substring(0, s.length() - 1)) + lastChar;
}

}
}

- modernphysics June 08, 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