注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
Given a series of questions based on the following:
- Think out loud — interviewers care more about your reasoning than the perfect answer.
- Reason from first principles — you won't recognize everything, and that's expected.
- Be ready to discuss tradeoffs — correctness, performance, edge cases, and what inputs could break the code.
- Brush up on async/concurrency — systems and concurrency concepts may come up.
- Get comfortable with order-of-magnitude thinking — memory, compute, and performance at scale, including CPU & memory dynamics.
- Please refrain from using an AI tools
-----
Asked to determine what a mystery_fn does. It converted integers into human readabln a fair random way).
Use a fixed size array with ten buckets, iterate through and collect the buckets. Then iterate through the buckets and generate the output.
With 100M digits in a compiled language like rust or c++
How long would this take?
The work:- 100M reads // count buckets
- 100M bucket bumps // buckets stay hot in cache
- 100M writes // generate sorted output
复制代码
Memory:- 100M u8 digits = ~100 MB input
- 100M usize digits = ~800 MB input on 64-bit
- output Vec<usize> = another ~800 MB if using usize
复制代码
for u8- CPU = ~3 GHz
- memory bandwidth = ~20-80 GB/s
- 100M [i] 1 byte = 100 MB
- Counting pass
- 100M [/i] 2 cycles / 3GHz ~= 0.07s
- 100M * 8 cycles / 3GHz ~= 0.27s
- Output pass
- 100 MB written
- 100 MB / 20 GB/s ~= 0.005s
- 100 MB / 80 GB/s ~= 0.001s
- accounting for loop overhead
- counting: ~0.07s-0.27s
- output: ~0.02s-0.15s
- total: ~0.1s-0.5s
复制代码
Also depends on input type. Parsing from strings could take seconds. |