Siemens Interview Question

In Programming round, They have chosen some problems and each problem may differ from each other. If you know how to solve in a simpler way. you will through.