Data Axle interview question

DSA code, where we had to compress a function and optimize it.