Given the average of elements in two arrays as ‘a’ and ‘b’ respectively, and their combined average as ‘c’, the task is to find the ratio of the number of elements in two array.
Input: a = 2, b = 8, c = 5 Output: 1:1 Input: a = 4, b = 10, c = 6 Output: 2:1
- Let the number of elements in two arrays are respectively x and y.
- So sum of all elements in the combined array is .
- Total number of elements in the combined array is and let .
- Here f is our required answer.
Below is the implementation of the above Approach:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Find the number which when added to the given ratio a : b, the ratio changes to c : d
- 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
- Sum of two numbers if the original ratio and new ratio obtained by adding a given number to each number is given
- 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
- Find nth Fibonacci number using Golden ratio
- Find combined mean and variance of two series
- Max count of unique ratio/fraction pairs in given arrays
- Average of remaining elements after removing K largest and K smallest elements from array
- Find common elements in three sorted arrays
- intersection_update() in Python to find common elements in n arrays
- Find a pair of elements swapping which makes sum of two arrays same
- Number of arrays of size N whose elements are positive integers and sum is K
- Find the average of k digits from the beginning and l digits from the end of the given number
- Divide the array into minimum number of sub-arrays having unique elements
- Count number of common elements between two arrays by using Bitset and Bitwise operation
- Range Queries to Find number of sub-arrays with a given xor
- Find the ratio of LCM to GCD of a given Array
- Find the number of sub arrays in the permutation of first N natural numbers such that their median is M
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.