2nd largest number in an array
Anonym
(1) nlogn. sorting. Or.If numbers have small range, use a each number's value as a index. Create a table, each number goes into the corresbonding index. when done, iterate backwards. Should give you O(n) time. (2) bit counter, right shift, &1. gives you number of ones. (3) two pointer, one goes one step at a time, another one goes two steps at a time. If they meet, then there is a loop. Further question: how can you find the start of the loop? .. ask me if anyone needs details.