Large distributed data center so-called “bigtable” receives a huge number of update queries every minute from servers all over the world. The engineers want to make the system works more efficiency, so they come up with a batch system for bigtable.
We can denote the data in the bigtable as an infinity text data. Every client can send commands to the bigtable server to editing the text. Once the client connects to the bigtable server, the cursor for the client is positioned before the first character of the text before performing any commands. The bigtable only supports three operations below:
When a new client connects the server, it sends all the operations to the bigtable. And then the next client can connect and perform its own operation list.
The batch system is designed to save the traffic volume. It merges all the clients operation together to one equivalent operation list. But their engineers soon noticed that it is hard to make the resulted operation list shortest.
They ask you, their senior programmer, to make up a solution, give the operation lists with minimum length and let the delete operations before the insert operations if possible.