Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are <code>24*60 = 1440</code> minutes per day. So you could easily brute force it, since you don't need to get more than on a minute basis accuracy. However I'm gonna describe a simple DP.</p> <p>You can create a boolean array that stores whether that minute has a class in it by one of the students in the group. You also have a second array. This array stores the number of open spaces in this block and to the left. So what you can do is traverse the boolean array from right to left and if the block has a class in it you make the number 0, otherwise you make it 1 plus the number in the minute prior.</p> <p>However, I feel my explanation lacking, so here is pseudo code:</p> <pre><code>blocked = &lt;boolean array&gt;; numtoleft = &lt;array containing the counts&gt;; if blocked[0]: numtoleft[0] = 0; else: numtoleft[0] = 1; for i = 1 to 1440-1: if blocked[i]: numtoleft[i] = 0; else: numtoleft[i] = numtoleft[i-1]; </code></pre> <p>Then you can easily find the biggest open slot by finding the maximum number in the 'numtoleft' array and you can add restrictions to the times you are looking at.</p> <p>EDIT:</p> <p>Here's the algorithm in python:</p> <pre><code>def largestslot(blocked, startminute, endminute): numtoleft = [0]*1440 numtoleft[startminute] = 0 if blocked[startminute] else 1 for i in xrange(startminute+1, endminute+1): numtoleft[i] = 0 if blocked[i] else 1 ansmax = max(numtoleft[startminute:endminute+1) ansi = numtoleft.index(ansmax) return (ansi-ansmax, ansi) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload