## Ebay Interview Question

Member Technical Staffs**Country:**India

**Interview Type:**In-Person

```
/**
* Returns n^k
* @param n
* @param k
* @return
*/
private static int power(int n, int k) {
System.out.println("Power " + n + " " +k);
if(k==0) return 1;
if(k==1) return n;
int temp=n,i=1;
while(i*2<k) {
System.out.println(temp);
System.out.println(i);
temp*=temp;
i*=2;
}
return temp*power(n,k-i);
```

}

superb!!

- techieDeep January 29, 2013