Arize Interview Experience - Worst interviewer ever
Summary
I interviewed at Arize and was asked to implement a multithreaded program that prints numbers from 0 to n using separate Zero, Odd, and Even threads.
Full Experience
The guy stayed quiet like a robot without uttering a word, smells toxicity. Anyway, here you go.
Posting the question here:
Problem Statement You need to print numbers in a sequence starting from 0 up to n. The sequence should look like: 0, 1, 2, 3, 4, ... , n The input will be a number n, and the program should print all numbers from 0 to n in order. Thread Requirements There will be three threads responsible for printing the numbers: Zero Thread Responsible for printing 0. The number 0 should be printed only once. Odd Thread Responsible for printing odd numbers: 1, 3, 5, 7, ... Even Thread Responsible for printing even numbers: 2, 4, 6, 8, ... Output Requirement Along with each number, the output must also indicate which thread printed the number. Example output format: 0 printed by ZeroThread 1 printed by OddThread 2 printed by EvenThread 3 printed by OddThread 4 printed by EvenThread ... n printed by respective thread Design Constraints There are some mandatory design considerations: You must implement three separate thread classes: ZeroThread OddThread EvenThread The business logic for printing numbers must remain inside the respective thread classes: Logic for printing 0 should be inside the ZeroThread class. Logic for printing odd numbers should be inside the OddThread class. Logic for printing even numbers should be inside the EvenThread class. The numbers must be printed strictly in sequence. The number 0 should appear exactly once in the output. Final Expected Behavior Given an input n, the output should be: 0 printed by ZeroThread 1 printed by OddThread 2 printed by EvenThread 3 printed by OddThread 4 printed by EvenThread ... n printed by the appropriate thread based on whether the number is odd or even.
Interview Questions (1)
Multithreaded Number Printing
You need to print numbers in a sequence starting from 0 up to n. The sequence should look like: 0, 1, 2, 3, 4, ... , n. The input will be a number n, and the program should print all numbers from 0 to n in order.
There will be three threads responsible for printing the numbers:
- Zero Thread: Responsible for printing 0. The number 0 should be printed only once.
- Odd Thread: Responsible for printing odd numbers: 1, 3, 5, 7, ...
- Even Thread: Responsible for printing even numbers: 2, 4, 6, 8, ...
The output must include which thread printed each number, e.g., 0 printed by ZeroThread, 1 printed by OddThread, etc.
Design constraints: implement three separate thread classes (ZeroThread, OddThread, EvenThread) with the printing logic inside each class, ensure numbers are printed strictly in sequence, and zero appears exactly once.