Standard Priority Queue VIII: Two Queues
This is an interesting problem where you do need a priority queue in order to simulate the game (remember to use Max-Color as the priority since the dequeuing is based on smaller priorities first), but the tricky part here is that you cannot enqueue in the main loop while each round simulation is going on otherwise you'll starve lower priority colors. Hence in the middle of the main simulation loop, instead of enqueuing, just save off the elements to be enqueued later. I used another pQueue for this reason, but you could have used a different data structure, pQueues are not necessary here. Code is down below, cheers, ACC. Multi Source Flood Fill - LeetCode You are given two integers n and m representing the number of rows and columns of a grid, respectively. You are also given a 2D integer array sources , where sources[i] = [r i , c i , color i ] indicates that the cell (r i , c i ) is initially colored with color i . Al...