Block Gemini Interview Question

optimising/creating an algorithm based on scenario given