title: Not being able to find an edge case in question "Process Tasks Using Servers" asked in leetcode weekly contest 243
body: <p>[link to the question] (<a href="https://leetcode.com/problems/process-tasks-using-servers/" rel="nofollow noreferrer">https://leetcode.com/problems/process-tasks-using-servers/</a>). The problem statement is clearly written in the provided link.
  I've highlighted a difference between my result and the expected result.</p>
  <p>I'm not able to figure out which edge case or condition I've missed?</p>
  <p>If the problem statement is still unclear then please do let me know.</p>
  <p><strong>Update</strong>: The updated solution is in the comment section.</p>
  <pre><code>import heapq
  class Solution:
      def assignTasks(self, servers: List[int], tasks: List[int]) -&gt; List[int]:
          serverPriority = [(name, index) for index, name in enumerate(servers)]
          
          # this sorts the server based on the priority order specified in the problem statement.
          serverPriority.sort()
           
          &quot;&quot;&quot;
           A new ID is given to the server after sorting, 
           which is basically the index number of the servers 
           in **serverPriority** list.
         &quot;&quot;&quot;
          serverId = [i for i in range(len(servers))]
          heapq.heapify(serverId)
          
          res = [-1] * len(tasks)
          
  
          runningServers = []
          heapq.heapify(runningServers)
          
          currTime = 0
          for j in range(len(tasks)):
              # if no servers are running then selects a server from the pool of available servers.
              if len(runningServers) == 0:
                  ID = heapq.heappop(serverId)
                  res[j] = serverPriority[ID][1]
                  
                  heapq.heappush(runningServers, (currTime + tasks[j], ID))
              else:
                  &quot;&quot;&quot;
                   if some servers are running then it checks whether any server
                   is going to stop execution at **currentTime**, or before that 
                   and then selects that server for running another task.
                  &quot;&quot;&quot;
                  if currTime &gt;= runningServers[0][0]:
                      time, ID = heapq.heappop(runningServers)
                      res[j] = serverPriority[ID][1]
                      
                      heapq.heappush(runningServers, (currTime + tasks[j], ID))
                  else:
                      &quot;&quot;&quot;
                       case when none of the running server can be chosen. 
                       so it chooses one from the pool.
                      &quot;&quot;&quot;
                      if len(serverId) &gt; 0:
                          ID = heapq.heappop(serverId)
                          res[j] = serverPriority[ID][1]
                          
                          heapq.heappush(runningServers, (currTime + tasks[j], ID))
                      else:
                          &quot;&quot;&quot;
                          If no servers are available in pool then it has to wait 
                           for one of the running server to stop.
                          &quot;&quot;&quot;
                          time, ID = heapq.heappop(runningServers)
                          currTime = time
                          res[j] = serverPriority[ID][1]
                          
                          heapq.heappush(runningServers, (currTime + tasks[j], ID))
              currTime += 1
              
          return res
  </code></pre>
  <p>Passed test cases:</p>
  <ol>
  <li>servers = [3,3,2], tasks = [1,2,3,2,1,2]</li>
  </ol>
  <ul>
  <li>expected: [2,2,0,2,1,2]</li>
  </ul>
  <ol start="2">
  <li>servers = [5,1,4,3,2], tasks = [2,1,2,4,5,2,1]</li>
  </ol>
  <ul>
  <li>expected: [1,4,1,4,1,3,2]</li>
  </ul>
  <p>Failed test case:</p>
  <ol>
  <li>servers = [338,890,301,532,284,930,426,616,919,267,571,140,716,859,980,469,628,490,195,664,925,652,503,301,917,563,82,947,910,451,366,190,253,516,503,721,889,964,506,914,986,718,520,328,341,765,922,139,911,578,86,435,824,321,942,215,147,985,619,865]</li>
  </ol>
  <p>tasks =[773,537,46,317,233,34,712,625,336,221,145,227,194,693,981,861,317,308,400,2,391,12,626,265,710,792,620,416,267,611,875,361,494,128,133,157,638,632,2,158,428,284,847,431,94,782,888,44,117,489,222,932,494,948,405,44,185,587,738,164,356,783,276,547,605,609,930,847,39,579,768,59,976,790,612,196,865,149,975,28,653,417,539,131,220,325,252,160,761,226,629,317,185,42,713,142,130,695,944,40,700,122,992,33,30,136,773,124,203,384,910,214,536,767,859,478,96,172,398,146,713,80,235,176,876,983,363,646,166,928,232,699,504,612,918,406,42,931,647,795,139,933,746,51,63,359,303,752,799,836,50,854,161,87,346,507,468,651,32,717,279,139,851,178,934,233,876,797,701,505,878,731,468,884,87,921,782,788,803,994,67,905,309,2,85,200,368,672,995,128,734,157,157,814,327,31,556,394,47,53,755,721,159,843]</p>
  <p>expected: [26,50,47,11,56,31,18,55,32,9,4,2,23,53,43,0,44,30,6,51,29,51,15,17,22,34,38,33,42,3,25,10,49,51,7,58,16,21,19,31,19,12,41,35,45,52,13,59,47,36,1,28,48,39,24,8,46,20,5,54,27,37,14,57,40,59,8,45,4,51,47,7,58,4,31,23,54,7,9,56,2,46,56,1,17,42,11,30,12,44,14,32,7,10,23,1,29,27,6,10,33,24,19,10,35,30,35,10,17,49,50,36,29,1,48,44,7,11,24,57,42,30,10,55,3,20,38,15,7,46,32,21,40,16,59,30,53,17,18,22,51,11,53,36,57,26,5,<strong>36,56</strong>,55,31,34,57,7,52,37,31,10,0,51,41,2,32,25,0,7,49,47,13,14,24,57,28,4,45,43,39,38,8,2,44,45,29,25,25,12,54,5,44,30,27,23,26,7,33,58,41,25,52,40,58,9,52,40]</p>
  <p>my result: [26,50,47,11,56,31,18,55,32,9,4,2,23,53,43,0,44,30,6,51,29,51,15,17,22,34,38,33,42,3,25,10,49,51,7,58,16,21,19,31,19,12,41,35,45,52,13,59,47,36,1,28,48,39,24,8,46,20,5,54,27,37,14,57,40,59,8,45,4,51,47,7,58,4,31,23,54,7,9,56,2,46,56,1,17,42,11,30,12,44,14,32,7,10,23,1,29,27,6,10,33,24,19,10,35,30,35,10,17,49,50,36,29,1,48,44,7,11,24,57,42,30,10,55,3,20,38,15,7,46,32,21,40,16,59,30,53,17,18,22,51,11,53,36,57,26,5,<strong>56,36</strong>,55,31,34,57,7,52,37,31,10,0,51,41,2,32,25,0,7,49,47,13,14,24,57,28,4,45,43,39,38,8,2,44,45,29,25,25,12,54,5,44,30,27,23,26,7,33,58,41,25,52,40,58,9,52,40]</p>