Optimize switching puzzle solution | Optiver Interview Question