Write a wrapper class for the file object which allows us to buffer the writes in-memory. The wrapper class, BufferedFile is initialized with a File class object and a buffer size. It has two methods: write and flush. The data should be flushed to disk when the buffer is full, or on demand with a method called flush. All bytes must be stored in the buffer first before being written to disk. The buffer cannot use more memory than the max bytes allowed.
Asked in the coding round 1 stage, this was a 60-minute coding round. The interviewer provided a FileOut interface with int write(char[] buf) and ran test cases at the end.
For Python grading, implement buffered_file_operations(chunks, buffer_size), where chunks is a list of strings. Return the list of strings written to the underlying file after all chunks are written and flush() is called.
def buffered_file_operations(chunks, buffer_size):