Orbitz Worldwide
4.0 of 5 301 reviews
www.orbitz.com Chicago, IL 1000 to 5000 Employees

Orbitz Worldwide Software Engineer II Interview Question

I interviewed in Chicago, IL and was asked:
"How can you solve n^m efficiently only using +, -, *, /."
Tags: algorithm
Add Tags [?]
Answer Flag Question

Part of a Software Engineer II Interview Review - one of 75 Orbitz Worldwide Interview Reviews

Answers & Comments

0
of 1
vote
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
}
- Interview Candidate on Dec 11, 2010 Flag Response
0
of 0
votes
int f(int n, int m)
{
   if(m==0) return 1;
   if(m==1) return n;
   n=n*f(n,(m-1));
   return n;
}
- ritvik on Feb 4, 2011 Flag Response
1
of 1
vote
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;
}
- Dhruv on Oct 18, 2011 Flag Response
1
of 1
vote
Disadvantage of recursion is the large amount of space on the stack for a large m in this case.
- Dhruv on Oct 18, 2011 Flag Response

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


Orbitz Worldwide – Why Work for Us?

Orbitz Worldwide (NYSE:OWW) is a leading global online travel company using technology to transform the way consumers around the world plan and purchase travel. Orbitz Worldwide operates the consumer travel planning… Full Overview

Provided by employer [?]

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

Glassdoor is your free inside look at Orbitz Worldwide interview questions and advice. All interview reviews posted anonymously by Orbitz Worldwide employees and interview candidates.