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 email@example.com. 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
- Longest Sub-array with maximum average value
- Maximum average sum partition of an array
- 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
- Find array elements that are greater than average
- Program for average of an array (Iterative and Recursive)
- Count pairs with average present in the same array
- Number of ways to choose elements from the array such that their average is K
- Find the deleted value from the array when average of original elements is given
- 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
- Bitwise AND of the sum of prime numbers and the sum of composite numbers in an array