Block Gemini interview question

optimising/creating an algorithm based on scenario given