M-DAQ interview question

Coding question from leet code