Qualcomm Interview Question for Software Engineer / Developers






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

It should be O(LogN) because it divides the number with N recursively
bool power(int M, int N)
{

int result = N/M;

if(result > M) return power(M,result);

else

if(result%M == 0)

return 1;

else

return 0;
}

- Taesung October 31, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Sorry for lines I am sure how I can control white space and line feed x_x

- Taesung October 31, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int Power(int m, int n) {
if n == 0
return 1;
else if n == 1
return m;
else
if n%2 == 0
tmp = Power(m, n/2);
return tmp*tmp;
else if n%2 == 1
tmp = Power(m, n/2);
return tmp*tmp*m;
}

e.g. m^5 = m^2*m^2*m = (m^1*m^1)*(m^1*m^1)*m=m*m*m*m*m

}

- jiez January 06, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@jiez..good solution..

- Mama January 09, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int power(int m,int n)
{
if(n==1)
return m;
return power(m,n/2)*power(m,n/2)
}
This is O(log N) and divide and conquer. The one given by Jiez is O(log n) and transform and conquer.

- Hersh January 18, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int power(int m,int n)
{
if(n==1)
return m;
return power(m,n/2)*power(m,n/2);
}
This is O(log N) and divide and conquer. The one given by Jiez is O(log n) and transform and conquer.

- Hersh January 18, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Man, the question itself has problem: there is always an O(N) effeciency for Power(M, N), since you actually don't save any '*' operation during divide and conquer, you have to have N-1 times of '*' operations. The reason why you don't save is operation '*' is 2 operand operations and it is transmisive. Consider m^8, you will divide eventually to (m*m)*(m*m) * (m*m)*(m*m), if you take all the parenthisis out, then you just have plain m*m*m*m*m*m*m*m, so there is no need to divide at all!

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

Exactly!
And the second question would be more interesting if the interviewer asks "find out if a given number N to be a power of M?" So you can extend first give the answer for "if N is a power of 2", which is easier, then just replace the 2 with M

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

If we try to solve the complexity of the problem, this is what we get..

let power(m,n) be T(n) and T(1) = m

T(n) = T(n/2) * T(n/2);
= T(n/4) * T(n/4) * T(n/4) * T(n/4)
= T(n/8) * T(n/8) * T(n/8) * T(n/8) * T(n/8) * T(n/8) * T(n/8) * T(n/8)..
= ...
= .. .
and so on till

T(n/n) + T(n/n) + .... n times ... + T(n/n)

which is equal to

m * m * m * m..... n number of times.

hence this is not in log(N)

- PradeepKashyap June 22, 2014 | 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