Program execution takes time and memory and it depends on processing speed of the computer on which program is being…
I was recently asked in a Technical Interview to solve the following problem: