You have a stream of bytes from which you can read one byte at a time. You only have enough space to store one byte. After processing those bytes, you have to return a random byte. Note: The probability of picking any one of those bytes should be equal

AnswerBot
2y
Return a random byte from a stream of bytes with equal probability.
Create a variable to store the count of bytes read
Create a variable to store the current random byte
For each byte read, generate a ra...read more
Help your peers!
Add answer anonymously...
Mentor Graphics Software Developer interview questions & answers
A Software Developer was asked Q. Given a matrix mat[m][n] where all the rows and columns are sorted non-decreasin...read more
A Software Developer was asked Q. Given a linked list with a loop, how would you find the starting point of the lo...read more
A Software Developer was asked Q. Given a directed graph, determine if it contains a cycle.
Popular interview questions of Software Developer
A Software Developer was asked Q1. Given a matrix mat[m][n] where all the rows and columns are sorted non-decreasin...read more
A Software Developer was asked Q2. Given a linked list with a loop, how would you find the starting point of the lo...read more
A Software Developer was asked Q3. Given a directed graph, determine if it contains a cycle.
>
Mentor Graphics Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

