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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- 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
- Average of a stream of numbers
- Find the average of first N natural numbers
- Find array elements that are greater than average
- Maximum average sum partition of an array
- 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
- Longest Sub-array with maximum average value
- Count pairs with average present in the same array
- Number of ways to choose elements from the array such that their average is K
- Partition an array of non-negative integers into two subsets such that average of both the subsets is equal
- Find the deleted value from the array when average of original elements is given
- Maximize the first element of the array such that average remains constant
- Program for average of an array (Iterative and Recursive)
- Find maximum average subarray of k length
- Find the subarray with least average
- Students with maximum average score of three subjects
- Longest subarray having average greater than or equal to x
- Longest subsequence whose average is less than K
- Longest subarray having average greater than or equal to x | Set-2