Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><em>I have designed a generic method for you where u can enter min, max size of balls(for buckets) and total number of balls</em></p> <p><strong>method to get number of buckets to be created.</strong></p> <pre><code>long getNoOfBucket(long total, int max, int min) { if (total % max &lt; min &amp;&amp; total % max != 0) { return (total / max) + 1; } else { return total / max; } </code></pre> <p><strong>method to get list of buckets.</strong></p> <pre><code> List&lt;List&lt;Long&gt;&gt; getbucketOfBuckets(long total, int max, int min) { List&lt;Long&gt; tempBucket = null; List&lt;List&lt;Long&gt;&gt; parentbucket = new ArrayList&lt;List&lt;Long&gt;&gt;(); if (total % max &lt; min &amp;&amp; total % max != 0) { long noOfBucket = getNoOfBucket(total, max, min); for (long i = noOfBucket; i &gt;= 1;i--) { if (total % max &lt; min &amp;&amp; total % max !=0) { total = total - min; long tempVar = total+1; tempBucket = new ArrayList&lt;Long&gt;(); for (long j = 1; j &lt;= min; j++) { tempBucket.add(tempVar); tempVar++; } parentbucket.add(tempBucket); } else { long tempmax = 0; if(total%max == 0){ tempmax = max; }else{ tempmax = total%max; } total = total - tempmax; long tempVar = total+1; tempBucket = new ArrayList&lt;Long&gt;(); for (int j = 1; j &lt;= tempmax; j++) { tempBucket.add(tempVar); tempVar++; } parentbucket.add(tempBucket); } } } else{ for (long i = noOfBucket; i &gt;= 1; i--) { total = total - max; long tempVar = total + 1; tempBucket = new ArrayList&lt;Long&gt;(); for (int j = 1; j &lt;= max; j++) { tempBucket.add(tempVar); tempVar++; } parentbucket.add(tempBucket); } } return parentbucket; </code></pre> <p><strong>main method to test above code</strong></p> <pre><code>public static void main(String[] args) { long total = Long.valueOf(args[0]); int max = Integer.valueOf(args[1]); int min = Integer.valueOf(args[2]); long noOfBucket = BallServicesImplementation.getNoOfBucket(total, max,min); List&lt;List&lt;Long&gt;&gt; parentBuclet = BallServicesImplementation.getbucketOfBuckets(total, max, min); for(List&lt;Long&gt; itr : parentBuclet){ System.out.println("size :: "+itr.size()); for(Long seLong : itr){ System.out.print(seLong+"\t"); } System.out.println(""); System.out.println("********************************************"); } </code></pre> <p>I have tested it under different test cases.u may try it and let me know if require some more improvement. hope it will help u.</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.
    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