ZL Technologies Interview Question

String and array questions of medium difficulty and asked to optimise