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.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- 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
- Maximize the first element of the array such that average remains constant
- 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
- Partition an array of non-negative integers into two subsets such that average of both the subsets is equal
- Average of remaining elements after removing K largest and K smallest elements from array
- Find ratio of zeroes, positive numbers and negative numbers in the Array