creating segment for sqrt decomposition

Solutions on MaxInterview for creating segment for sqrt decomposition by the best coders in the world

showing results for - "creating segment for sqrt decomposition"
Walid
27 Oct 2016
1int segment[10000];
2int preprocess(int input[], int n) { 
3    int current_segment = -1; 
4    int segment_size = sqrt(n); 
5   
6    for (int i=0; i<n; i++) { 
7        if (i % segment_size == 0) { 
8            current_segment++;  //new segment
9        } 
10        segment[current_segment] += input[i]; 
11    } 
12    
13    return segment_size;
14}
15