1. Use Power function in log time 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; }
2. Use hash for duplicate numbers in the set.
I am still trying to understand the rationale behind this question. |