Interview Question

Software Engineer Interview

-Sydney

Google

You have a 64bit interger counter set to 0. How long it will take to overflow the counter given that you are incrementing it at 4Ghz speed.

AnswerAdd Tags

Interview Answers

9 Answers

10

If we were to keep it simple and not consider every increment to be a load, increment, store then we basically need 2^64 increments to make the long overflow. 4GHz means 4*(2^30) instructions per second.. which is 2^32 effectively it is (2^64)/(2^32) = 2^32 seconds.. or roughly 136years.

Praveen on

0

python: (float(2**64)/(4*10**9))/(24*60*60*365) 146.235604338768 years.

Anonymous on

2

guys note: the counter is initialized to 0. and overflows when you increment the counter when it holds 2^32.

Vivek on

0

its take 2 second right

fasahat khan from karachi pakistan B-64 blk 4-A Gulshan e iqbal karachi journalist society 75300 on

2

total increments before overflow (tibo) = 2^64 increment speed(is) = 1 second / (4*10^9) increments | 4Ghz = 1x10^9 Hz total seconds (ts) = 2^64 increments * (1 second /(4*10^9) increments) ts = 4.611 * 10^9 seconds total years = ts/(60*60*24*52) = 146.2 years

Parag on

0

total years = ts/(60*60*24*7*52) = 146.2 years and 4ghz = 4*10^9 Hz

correction(s) to above on

1

Please read the question carefully, it says counter is incrementing at the rate of 4GHz. i.e, 4GB per second. Not incrementing every second. So after elapsing first second, counter is at 4GB. After elapsing 2nd second, it is 4 + 4 = 8GB. 64 bit integer is, 2^64 = 2^32 * 2^32. Which is roughly 4GB * 4GB = 16GB. So per second counter incremented to 4GB, so for 16GB it takes 4 seconds.

Anonymous on

1

Anonymous: 4GB * 4GB != 16 GB. You're ignoring the units! To be accurate, the answer is 4G * 4G = 16 G^2 = 16 * 2^30 * 2^30.

donutello on

0

60 years

grad stud on

Add Answers or Comments

To comment on this, Sign In or Sign Up.