Given the range of cost from lowCost to upCost and range of quantity from lowQuant to upQuant, find if it is possible to get a given ration ratio r where , and lowCost <= cost <= upCost and lowQuant <= quantity <= upQuant.
Input : lowCost = 1, upCost = 10, lowQuant = 2, upQuant = 8 r = 3 Output : Yes Explanation: cost / quantity = 6 / 2 = 3 where cost is in [1, 10] and quantity is in [2, 8] Input : lowCost = 14, upCost = 30, lowQuant = 5, upQuant = 12 r = 9 Output : No
Approach: From the given formula, following equation can be easily deduced: . From this equation, logic can be easily deduced. Check the product of every value of quantity with r and if any value of the product lies between lowCost and upCost, then answer is Yes otherwise it is No.
Below is the implementation of above approach:
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.
- Find the sum of the costs of all possible arrangements of the cells
- Sum of two numbers if the original ratio and new ratio obtained by adding a given number to each number is given
- Find the number which when added to the given ratio a : b, the ratio changes to c : d
- Ratio of mth and nth terms of an A. P. with given ratio of sums
- Choose points from two ranges such that no point lies in both the ranges
- Check if quantities of 3 distinct colors can be converted to a single color by given merge-pair operations
- Count distinct median possible for an Array using given ranges of elements
- Minimum change in given value so that it lies in all given Ranges
- Find speed of man from speed of stream and ratio of time with up and down streams
- Program to find the count of coins of each type from the given ratio
- Find amount to be added to achieve target ratio in a given mixture
- Find the ratio of LCM to GCD of a given Array
- Find all ranges of consecutive numbers from Array
- Queries for maximum difference between prime numbers in given ranges
- P - smooth numbers in given ranges
- Find the ratio of number of elements in two Arrays from their individual and combined average
- Find ratio of zeroes, positive numbers and negative numbers in the Array
- Find nth Fibonacci number using Golden ratio
- Program to find the common ratio of three numbers
- Find pair with maximum ratio in an Array
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.
Improved By : jit_t