Implement tac, the reverse of cat: given a file, print its lines starting from the last line and ending with the first. Once the simplest version works, the interviewer keeps asking you to optimise it: 1. Reduce the extra space to O(1). 2. Then, setting space and time complexity aside,…