File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -229,14 +229,24 @@ public Integer getMedianAmplificationLevel(Integer[] inArr) {
229
229
230
230
Integer freqSum = inList .stream ().mapToInt (e -> e ).sum ();
231
231
232
- Integer middleVal = freqSum / 2 ;
232
+ Integer freqByLevel [] = new Integer [inArr .length ];
233
+ int count = 1 ;
234
+ for (int i = 0 ; i < inList .size (); i ++) {
235
+ freqByLevel [i ] = count * inList .get (i );
236
+ count ++;
237
+ }
238
+ Integer freqByLevelSum = sum (freqByLevel );
239
+
240
+ Integer middleVal = freqByLevelSum / 2 ;
233
241
Integer cumSum = 0 , median = 0 ;
234
-
235
- for (int i = 0 ; i < inArr .length ; i ++) {
242
+ System . out . println ( freqByLevelSum + " " + middleVal );
243
+ for (int i = 0 ; i < freqByLevel .length ; i ++) {
236
244
if (cumSum > middleVal ) {
245
+ System .out .println (cumSum );
237
246
break ;
238
247
}
239
- cumSum += inArr [i ];
248
+ System .out .println (cumSum );
249
+ cumSum += freqByLevel [i ];
240
250
median ++;
241
251
}
242
252
You can’t perform that action at this time.
0 commit comments