Given a sequence of positive integers a1, a2, …, an. Find all such indexes i such that the i-th element equals the arithmetic mean of all other elements (that is all elements except for this one).
Input : 5 1 2 3 4 5 Output : 1 no. of elements 2 index of element Average of 1, 2, 4 & 5 is 3 so the output is single index i.e. 3. Input : 4 50 50 50 50 Output : 4 no. of elements 0 1 2 3 index of element Average of 50, 50, 50 & 50 is 50 and all the indexes has the same i.e. 50 so the output is indexes 1, 2, 3 & 4.
Time Complexity: O(n)
This article is contributed by Sagar Shukla. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Average of a stream of numbers
- Find the average of first N natural numbers
- Maximum average sum partition of an array
- Longest Sub-array with maximum average value
- Count the number of sub-arrays such that the average of elements present in the sub-array is greater than that not present in the sub-array
- Count pairs with average present in the same array
- Program for average of an array (Iterative and Recursive)
- Find array elements that are greater than average
- Number of ways to choose elements from the array such that their average is K
- Count occurrences of the average of array elements with a given number
- Average of remaining elements after removing K largest and K smallest elements from array
- Partition an array of non-negative integers into two subsets such that average of both the subsets is equal
- Print all distinct integers that can be formed by K numbers from a given array of N numbers
- Rearrange numbers in an array such that no two adjacent numbers are same
- Minimum number greater than the maximum of array which cannot be formed using the numbers in the array