Bloomberg LP Interview Question for Interns


Country: United States
Interview Type: Phone Interview




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

Simple trick would be to reverse a number and check if it is equal to original number.
If yes, number is a palindrome.

main()
{
int temp1, temp2;
int n=0;
printf("Number plz");
scanf("%d",&temp1);
temp2=temp1;
while(temp2!=0)
{
n=n*10;
n=n+temp2%10;
temp2=temp2/10;
}
if(temp1==n)
printf("palindrom found");
else
printf("no palindrome");
}

- ashishB February 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

// convert to a string then compare
bool palindrome(int a){
int size = 0, temp = a;
while( temp /= 10) size++;
char str[size + 1];
sprintf(str, "%d", a);
char *start = str;
char *end = str + size - 1;
while(end > start){
if(*start != *end) return false;
start ++;
end --;
}
return true;
}

- RK January 25, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I have three methods, first, if we can use extra space we can use sprintf to convert int to string to judge whether this int is a palindrome. Second, we use / operator to reverse the int and judge whether the reversed number and the raw number are equal. Third, I will give you my program here. A very important point is that the second method maybe cause overflow.

#include<stdio.h>
#include<string.h>

int auxiliary(char *p_start, char *p_end) {
while(p_start < p_end) {
if(*p_start != *p_end) {
break;
}
p_start++;
p_end--;
}
if(p_start >= p_end) {
return 1;
} else {
return 0;
}
}

int is_palindrome1(int n) {
char s[10] = {'\0'};
sprintf(s, "%d", n);
int len = strlen(s);
char *p_start = s;
char *p_end = s + len - 1;
if(auxiliary(p_start, p_end)) {
return 1;
} else {
return 0;
}
}

int is_palindrome2(int n) {
int value = 0;
int temp = n;
while(temp) {
value = value * 10 + temp % 10;
temp /= 10;
}
if(value == n) {
return 1;
} else {
return 0;
}
}

int is_palindrome3(int n) {
int div = 1;
int temp = n;
int first, last;
while(temp >= 10) {
div *= 10;
temp /= 10;
}
while(n) {
first = n / div;
last = n % 10;
if(first != last) {
break;
}
n = (n % div) / 10;
div /= 100;
}
if(n == 0) {
return 1;
} else {
return 0;
}
}

void main() {
int n = 12344321;
if(is_palindrome3(n)) {
printf("yes\n");
} else {
printf("no\n");
}
getchar();
}

- yingsun1228 January 25, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) {
		String s = new Integer(12521).toString();
		StringPalindrome stringPalindrome = new StringPalindrome();
		System.out.println(stringPalindrome.checkPalindrome(s,0,s.length()-1));

	}

	private boolean checkPalindrome(String s,int start, int end ){
		while(start <= end){
			if(s.charAt(start) == s.charAt(end)){
				start++;end--;
			}else return false;
			
		}
		return true;
		
		
		
	}

- Nits March 14, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class palindrome {

	private static Scanner input;

	public static void main(String[] args) {
		input = new Scanner(System.in);
		String userIp = input.next();
		int len = userIp.length();
		int mid = len/2;
		int i=0;int left,right;
		boolean flag= true;
		for(i=0;i<mid;i++){
			left = mid+i;
			right = mid-i;
			if(userIp.charAt(left) != userIp.charAt(right)){
				System.out.println("Not Palindrome");
				flag = false;
				}
		}
		if(flag)
			System.out.println("Palindrome");
	}

}

- karpagaganesh March 08, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream.h>
#include<conio.h>
void main()
{
int num,a,rev,sum=0;
clrscr();
cout<<"enter a number";
.cin>>num;
rev=num;
while(num!=0)
{
a=num%10;
sum=sum+a;
num=num/10;
}
if(rev==sum)
{
cout<<"no. is palindrome";
}
else
{
cout<<"not a palindrome"
}
getch();
}

- pcmchoudhary007 April 10, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 3 vote

bool isPalindrome(int number)
{
   int d[50],i =0;
    while(int digit = number %10, number >>1 !=0)
{
d[i++]=digit;
}
for(int j=0;j<i/2;j++)
 if(d[j]!=d[i-j])
return false;
}
return true;

- Anonymous January 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

}

- Anonymous January 23, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

It doesn't seem to work

- isandesh7 January 29, 2013 | Flag


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