Work in HR or Recruiting?
Orbitz Worldwide
3.9 of 5 218 reviews
www.orbitz.com Chicago, IL 1000 to 5000 Employees

52 interview experiences Back to all Orbitz Worldwide Interview Questions & Reviews

Interview Question for Software Engineer II at Orbitz Worldwide:
Dec 11, 2010

How can you solve n^m efficiently only using +, -, *, /.


Tags: algorithm
Add Tags [?]

See more for this Orbitz Worldwide Software Engineer II Interview

Helpful Question?  
Yes | No
Inappropriate?

Answers & Comments (4)

0 of 1 people found this helpful

Dec 11, 2010

by Interview Candidate:

This is one solution that doesn't deal with negative exponents
exp(n, m) {
  if (m == 0) return 1
  if (m == 1) return n
  exp = exp(n, m / 2)
  if ( isOdd(m) )
    exp = exp * n
  return exp
}
Helpful Answer?  
Yes | No
Inappropriate?

Feb 4, 2011

by ritvik:

int f(int n, int m)
{
   if(m==0) return 1;
   if(m==1) return n;
   n=n*f(n,(m-1));
   return n;
}
Helpful Answer?  
Yes | No
Inappropriate?

1 of 1 people found this helpful

Oct 18, 2011

by Dhruv:

There is no need to solve it recursively.
it is pretty simple
int calculateExp(int n, int m) {
     exp = n
     for (i = 1; i <= m; i++) {
           exp = exp*n
     }
     return exp;
}
Helpful Answer?  
Yes | No
Inappropriate?

1 of 1 people found this helpful

Oct 18, 2011

by Dhruv:

Disadvantage of recursion is the large amount of space on the stack for a large m in this case.
Helpful Answer?  
Yes | No
Inappropriate?

To comment on this question, Sign In with Facebook or Sign Up

Orbitz Worldwide – Why Work for Us?

We are a leading global online travel company that uses innovative technology to enable leisure and business travelers to research, plan and book a broad range of travel products. Orbitz is part of the Orbitz Worldwide… Full Overview

Provided by employer [?]

Tags are like keywords that help categorize interview questions that have something in common.