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:
- Generate an array B from the given array A which satisfies the given conditions
- Generate an array of size K which satisfies the given conditions
- Check if the Matrix satisfies the given conditions
- Maximum length sub-array which satisfies the given conditions
- Partition the digits of an integer such that it satisfies a given condition
- Find the lexicographically smallest string which satisfies the given condition
- Find permutation of first N natural numbers that satisfies the given condition
- Find count of numbers from 0 to n which satisfies the given equation for a value K
- Find the minimum value of m that satisfies ax + by = m and all values after m also satisfy
- Smallest index in the given array that satisfies the given condition
- Construct a Matrix of size NxN with values in range [1, N^2] as per given conditions
- Range sum queries based on given conditions
- Maximum size of sub-array that satisfies the given condition
- Subarray permutation that satisfies the given condition
- Digital Root (repeated digital sum) of square of an integer using Digital root of the given integer
- Minimum decrements to make integer A divisible by integer B
- Find numbers a and b that satisfy the given conditions
- Find the number of unique pairs satisfying given conditions
- Number of K's such that the given array can be divided into two sets satisfying the given conditions
- Generate an array using given conditions from a given 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 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.