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.
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.
- 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
- Find array elements that are greater than average
- Count pairs with average present in the same array
- Program for average of an array (Iterative and Recursive)
- Maximize the first element of the array such that average remains constant
- 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
- Number of ways to choose elements from the array such that their average is K
- 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
- Find ratio of zeroes, positive numbers and negative numbers in the Array
- Print all distinct integers that can be formed by K numbers from a given array of N numbers
- Fill the missing numbers in the array of N natural numbers such that arr[i] not equal to i
- Bitwise AND of the sum of prime numbers and the sum of composite numbers in an array
- Rotate all odd numbers right and all even numbers left in an Array of 1 to N
- Rearrange numbers in an array such that no two adjacent numbers are same