Tech Mahindra interview question

Coding Question based on the Data Structure