jugaad
BAN USER1. Keep maintaining sum of odd numbers until the sum is greater than the given numer. ex: if 10 is given (1+3+5+7 = 16) is just greater than 10. (1+3+5=9) is smaller than 10
2. As the count of odder numbers added is 4, we can assume the square root of number will be between 3 and 4.
3. To find decimal part we can extrapolate the number. ex: in above case, 4-3/16-10 = 1/6=0.16
4. so square root is approx 3.16
1. initialize 3 dimentioanl array to cache the intermediate sums. arr[4][4][4]
2. start 2 nested loops and traverse through first 2 arrays, populate arr[4][4][0].
3. start 1 loop to calculate all other 2 dimensional planes. keep track of the sum for which matches the asked sum.
4. solution is done in n^2, which otherwise would have taken n^3 as brute force approach.
In java
- jugaad April 28, 20161. Initialize queue for dateTime class.
2. Maintain a counter to track number of elements in queue at given time.
3. For recordHit(), make current timestamp entry in queue (BlockingQueue in java).
4. For getCounter(), keep dequeue expired values from queue. return the counter.
5. Create a timertask in java which runs in separate thraed and keep queue in sync by removing expired entries.