Note that there are some explanatory texts on larger screens.

plurals
  1. POFaster algorithm for counting active calls
    primarykey
    data
    text
    <p>We are implementing a density report for a call center. The result must be displayed as table with a row per day showing the maximum number of <strong>simultaneously</strong> active calls during that day. </p> <p>We are building the lib behind the UI. The contract specifies we receive the number of calls for that day and two arrays of integers, one with the start time and one with the end time of each call, so, for example:</p> <p>For a given day just two calls are received: One goes from time 20 to 30 and the other one from 10 to 20. The maximum number simultaneously calls is 1. </p> <p>On the other hand, for another day, also two calls are received, one from 10 to 45 and the other from 15 to 40 then the maximum number of simultaneously calls is 2. </p> <p>The contract for the web service is this</p> <pre><code>public static int GetMaxDensity(int N, int[] X, int[] Y) </code></pre> <p>And the data looks like this (suppose 3 calls where received that day). First one from 10 to 25, second one from 12 to 30 and third one from 20 to 23.</p> <pre><code>N = 3, X = {10, 12, 20} Y = {25, 30, 23} </code></pre> <p>And the return must be: 3.</p> <p>I've implemented this solution:</p> <pre><code>public static int GetMaxDensity(int N, int[] X, int[] Y) { int result = 0; for (int i = 0; i &lt; N; i++) { int count = 0, t = X[i]; for (int j = 0; j &lt; N; j++) { if (X[j] &lt;= t &amp;&amp; t &lt; Y[j]) count++; } result = Math.max(count, result); } return result; } </code></pre> <p>And it works great when the number of calls is up to 1000 (weekends) but within work days the number is pretty big and the calculation takes so long (>5 minutes). I now the reason could be my solution is using two nested cycles but I don't have pretty much experience with complex algorithms so my question is:</p> <p>Given that I just need the maximum number of simultaneously calls (not the times nor the callers), which could be a faster way to perform this calculation if there is one.</p>
    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.
 

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