Perennial System Interview Question

coding problem based on loops