Given integers x and y which denotes the average temperature of the week except for days Day1 and Day2 respectively, and the sum of the temperature of Day1 and Day2 as S, the task is to find the temperature of the days Day1 and Day2.
Input: x = 15, y = 10, S = 50
Output: Day1 = 10, Day2 = 40
The average of week excluding Day1 is 15, the average of week excluding Day2 is 10 and the sum of temperature of Day1 and Day2 is 50. Individual temperature of the two days are 10 and 40 respecticvely.
Input: x = 5, y = 10, s = 40
Output: Day1 = 35, Day2 = 5
The average of week excluding Day1 is 5, the average of week excluding Day2 is 10 and the sum of temperature of Day1 and Day2 is 40. Individual temperature of the two days are 35 and 5 respecticvely.
Approach: We know that Average = sum of all observation / total number of observation. Hence, the sum of observation = Average * number of observation i.e., S = A * n
So after excluding Day1 or Day2 we are left with only 6 days
so N = 6 and the equations are:
on subtracting the above two equations we get,
and it is given in the problem statement that
Solving the above two equations, the value of Day1 and Day2 is given by:
[Tex]Day1 = S – Day2 [/Tex]
Below is the implementation of above approach:
Day1 : 35 Day2 : 5
Time Complexity: O(1)
Auxliary Space: O(1)
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.
- Total number of days taken to complete the task if after certain days one person leaves
- Find the day of the week after K days from the given day
- Find number of days between two given dates
- Find the subarray with least average
- Find the missing value from the given equation a + b = c
- Find average of two numbers using bit operation
- Find the average of first N natural numbers
- Find the Batting Average of a batsman
- Find n-variables from n sum equations with one missing
- Puzzle 40 | (Find missing Row in Excel)
- Find the Missing Point of Parallelogram
- Program to find simple moving average
- Find the repeating and the missing number using two equations
- Find the missing number in Arithmetic Progression
- Find the last two missing digits of the given phone number
- Find the deleted value from the array when average of original elements is given
- Find the missing number in unordered Arithmetic Progression
- Convert a given temperature to another system based on given boiling and freezing points
- Find the smallest positive number missing from an unsorted array | Set 3
- Find the ratio of number of elements in two Arrays from their individual and combined average
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.