Bloomberg LP Interview Question for Software Engineers


Country: United States
Interview Type: In-Person




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

def pow(x, n):
        if n == 0:
            return 1
        neg = False
        if n < 0:
            neg = True
            n = -n
        pow = 1
        while n > 1:
            if n % 2 == 1:
                pow *= x
            n /= 2      # x^n = (x ^ 2) ^ (n / 2)
            x *= x
        return 1/(pow * x ) if neg else pow * x

Looking for interview experience sharing and mentors?
Visit A++ Coding Bootcamp at aonecode.com.

Given by experienced engineers/interviewers from FB, Google and Uber,
our ONE TO ONE courses cover everything in an interview including
latest interview questions sorted by companies,
SYSTEM DESIGN Courses (highly recommended for people interviewing with FLAG)
ALGORITHMS (conquer DP, Graph, Greedy and other advanced algo problems),
and mock interviews.

Our students got offers from G, U, FB, Amz, Yahoo and other top companies after a few weeks of training.

Welcome to email us aonecoding@gmail.com with any questions. Thanks for reading.

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

double power(int x, int n)
{
if (n < 0) return 1/pow(x,n);
else return pow(x,n);
}

double pow (int x, int n)
{
if (n == 0) return 1;

double v = power(x, n >> 1);

if (x % 2 == 0) return v*v;
else return v*v*x;
}

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

@ aonecoding :
How your case handles fractional power?

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

public static double pow(int x, int y) {
if(y == 0) return 1;
if(x == 0) return 0;
if(y < 0) return 1/pow(x, Math.abs(y));
String[] ind = Integer.toString(y).split(".");
int indd = Integer.toString(y).indexOf(".");
if(ind.length > 1 && Integer.parseInt(ind[1]) > 0){
int denom = 1;
while(indd++ < Integer.toString(y).length()-1) denom *= 10;
return pow(x,Integer.parseInt(ind[0] + ind[1]))/pow(x,denom);
} else {
return x*pow(x, y-1);
}
}

- kupu May 08, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public int power(int number, int power) { int powerNumber=1;while(power !=0) { powerNumber = powerNumber * number;
power--;}

- Hemu June 17, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{}

- Anonymous January 18, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote
{{{ int r =4; int n = 20; long double r=1; for (int i = 1; i <= n; ++i) { r*=x; } std::cout << "V=" << r; std::cout <<", STD=" << std::pow(x, n) << std::endl; - Anonymous January 18, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

iint pow(int x, int y){
if(y == 0){
return 1;
}
if(y == 1){
return x;
}
int temp = pow(x, y/2);
if(y%2 ==0){
temp = temp * temp;
}else{
temp = x * temp * temp;
}
return temp;
}

- thehacker January 19, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int pow(int x, int y){
if(y == 0){
return 1;
}
if(y == 1){
return x;
}
int temp = pow(x, y/2);
if(y%2 ==0){
temp = temp * temp;
}else{
temp = x * temp * temp;
}
return temp;
}

- visualvm January 19, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static int power(int num, int pow) {
		int res=1;
		while(pow >= 1) {
		res= num *	res;
			pow --;
		}

- mrmjap June 04, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int pow(int x, int n)
{
if(n == 0)
return 1;

return x * pow(x, n-1);
}

- wayne June 06, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int pow(int x, int n)
{
    return n == 0 ? 1 : x * pow(x, n-1);
}

- wayne June 06, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int pow(int x, int n)
{
    return n == 0 ? 1 : x * pow(x, n-1);

}

- wayne June 06, 2018 | 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