MCPcopy Create free account
hub / github.com/Rohit91singh9/Coding-DP-DSA / Result

Class Result

findEarliestMonth.java:1–29  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Result
2{
3 static int findEarliestMontth(int arr[]){
4 int month=0;
5 int change=Integer.MAX_VALUE;
6 int tsum=0;
7 int s=0;
8 int n=arr.length;
9 for(int i=0;i<n;i++){
10 tsum+=arr[i];
11 }
12 int avg1=0,avg2=0;
13 for(int i=0;i<n;i++){
14 s+=arr[i];
15 avg1=s/(i+1);
16 avg2=tsum/n;
17 if(Math.abs(avg1-avg2)<change){
18 change=Math.abs(avg1-avg2);
19 month=i+1;
20 }
21 }
22 return month;
23 }
24 public static void main (String[] args) throws java.lang.Exception
25 {
26 int arr[]={1,3,2,3};
27 System.out.println(findEarliestMontth(arr));
28 }
29}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected