Himanshu Singh
BAN USER 0of 0 votes
AnswerHow to divide a circular array into k group of contiguous element such that difference between maximum sum and minimum sum is minimum. Each group have contiguous element of array. For e.g If the array is as follow. [6 13 10 2] and k=2 then o/p should be 18(6+10+2)13=5. As array is circular 6,10,2 are contiguous element of array.
 Himanshu Singh in India
For e.g If the array is as follow. [6 13 2 10] and k=2 then o/p should be 16(6+10)15(13+2)=1. As array is circular 6,10 are contiguous element of array.
For e.g If the array is as follow. [100 92 133 201 34 34 34 94 108] and k=4 then group as follow 208(108,100), 225(92,133), (201), 196(34,34,34,94) so 225196=29 Report Duplicate  Flag  PURGE
Samsung Software Developer Algorithm
You code doesn't works for test case 2.
We can finish all three packets within 10 secs using 1 CPU only.
package general;
import java.util.Arrays;
import java.util.TreeMap;
public class SieveOfEratosthenese {
public static void getPrimesBySeieveOfEraosthenes(int n, boolean primes[]) {
for(int i=2; i<= Math.sqrt(n); i++){
if(primes[i]){
for(int j=i*i;j<=n; j+=i){
primes[j] = false;
}
}
}
}
public static void main(String[] args) {
// TODO Autogenerated method stub
int n = 16;
boolean[] primes = new boolean[n+1];
Arrays.fill(primes, true);
getPrimesBySeieveOfEraosthenes(n, primes);
for (int i = 2; i <= n; i++) {
if (primes[i])
System.out.print((i) + " ");
}
TreeMap <Integer, Integer> sums = new TreeMap<>();
int sum =0;
for (int i = 2; i <= n; i++) {
if (primes[i]){
sums.put(i1, sum);
sum +=i;
}
}
if(primes[n]){
sums.put(n,sum);
}
System.out.println( "\n"+ sums.get(sums.ceilingKey(4)));
}
}

Himanshu Singh
January 23, 2019
Repstacimdalton, Dev Lead at ASAPInfosystemsPvtLtd
At the moment I'm implementing Slinkies in the financial sector. My current pet project is researching break up a ...
Repcrystalblibby, Analyst at Achieve Internet
By professional i am teacher. Successfully supervised and assisted students, grade artwork, encouraged creativity and new technique.Familiar with art ...
Open Chat in New Window
This question had been asked recently in samsung r&d test. ! NoName solution will not pass all test case(s).
 Himanshu Singh March 09, 2019