design algorithm with threads

0
CPP
cpp
OUTPUT