Walmart Labs Interview Question for Java Developers


Country: United States
Interview Type: In-Person




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

public static int powerRecursive(int num,int pow) {
		if (pow < 1) 
			return 1; 
		else
			return num * powerRecursive(num, pow-1) ;
	}
	public static int pow(int base , int exp)
	{

		if(exp <= 1) return base;
		
		int total = 1;
		
		for(int i = 0; i < exp; i++)
		{   
			total = (base * total);
		}
		return total;

}

- schemaless October 11, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

what if the task assumes that x and y can be of float or double type?

- zr.roman December 08, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static int powerRecursive(int num,int pow) {
		if (pow < 1) 
			return 1; 
		else
			return num * powerRecursive(num, pow-1) ;
	}
	public static int pow(int base , int exp)
	{

		if(exp <= 1) return base;
		
		int total = 1;
		
		for(int i = 0; i < exp; i++)
		{   
			total = (base * total);
		}
		return total;  


	}

- schemaless October 11, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think we should use Divide and Conquer for efficiency when we impletement recursive version.

int powerRecursive(int num,int pow)
{
    if (pow == 0)
    {
        return 1;
    }

    if (pow == 1)
    {
        return num;
    }

    int half = powerRecursive(num, pow/2);
    if (pow % 2 == 0)
    {
        return half * half;
    }
    else
    {
        return half * half * num;
    }
}

- Guozi149 October 12, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/* Function to calculate x raised to the power y in O(logn)*/
int power(int x, unsigned int y)
{
    int temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}

- Nit October 14, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/* Function to calculate x raised to the power y in O(logn)*/
int power(int x, unsigned int y)
{
    int temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}

- Nit October 14, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/* Function to calculate x raised to the power y in O(logn)*/
int power(int x, unsigned int y)
{
    int temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}

- Anonymous October 14, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

}

- Anonymous October 14, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- Anonymous October 14, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

good

- Anonymous November 17, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

good

- gggggg November 17, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static double power(double base, double basePow)
    {
         
        if(basePow==0)
        {
            return 1;
        }
        else if(basePow==1)
        {
            return base;
        }
        else if(basePow>1)
        {
            return base*power(base,basePow-1);
        }
        else
        {
 
              return 1/power(base, -1 * basePow);
        }
        
        
    }

- mohdsalmanshaikh63 January 10, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def pow(x,y):
    if(y==0): 
        return 1
    if(y==1): 
        return x
    if(y<0): 
        return 1/pow(x,abs(y))
    if(y%2==0):
        r = pow(x,y/2)
        return r*r
    else :
        r = pow(x,(y-1)/2)
        return r*r*x    
print(pow(3,-3))

- cnkumar20 August 04, 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