Given two integers L and R where L ≤ R, the task is to find an integer K such that:
- L ≤ K ≤ R.
- All the digits of K are distinct.
- The value of the expression (L – K) * (K – R) is maximum.
If multiple answers exist then choose the larger value for K.
Input: L = 5, R = 10
Input: L = 50, R = 60
Approach: Iterate from L to R and for each value of K, check whether it contains all distinct digits and (L – K) * (K – R) is maximum. If two or more values give the same maximum value for the expression then choose the greater value for K.
Below is the implementation of the above approach:
- Check if the Matrix satisfies the given conditions
- Maximum length sub-array which satisfies the given conditions
- Generate an array of size K which satisfies the given conditions
- Partition the digits of an integer such that it satisfies a given condition
- Generate an array B from the given array A which satisfies the given conditions
- Find the minimum value of m that satisfies ax + by = m and all values after m also satisfy
- Find the lexicographically smallest string which satisfies the given condition
- Find permutation of first N natural numbers that satisfies the given condition
- Find numbers a and b that satisfy the given conditions
- Biggest integer which has maximum digit sum in range from 1 to n
- Minimum positive integer divisible by C and is not in range [A, B]
- Maximum positive integer divisible by C and is in the range [A, B]
- Find the number of unique pairs satisfying given conditions
- Minimum integer such that it leaves a remainder 1 on dividing with any element from the range [2, N]
- Find whether a given integer is a power of 3 or not
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.