![]() |
VOOZH | about |
Given a range [start, end], find the largest palindromic number in the range and check if it is divisible by the smallest prime number in the range.
Examples:
Input: start = 1, end = 500
Output: true
Explanation: The largest palindromic number in the range is 484, which is divisible by the smallest prime number 2 in the range.Input: start = 50, end = 1000
Output: false
Explanation: The largest palindromic number in the range is 999, which is not divisible by the smallest prime number 53 in the range.Input: start = 1, end = 10
Output: false
Explanation: The largest palindromic number in the range is 9, which is not divisible by the smallest prime number 2 in the range.
Approach: This can be solved with the following idea:
- Start iterating from the end toward the start of the given range.
- For each number, check if it is a palindrome. If yes, store it as the largest palindrome number found so far and break the loop.
- Find the smallest prime number in the range.
- Check if the largest palindrome number found in step 2 is divisible by the smallest prime number found in step 3.
- Return the result.
Below are the steps for the above approach :
Below is the code for the above approach :
True False
Time Complexity: O(N2)
Auxiliary Space: O(1)