2396. Strictly Palindromic Number LeetCode Solution

In this guide, you will get 2396. Strictly Palindromic Number LeetCode Solution with the best time and space complexity. The solution to Strictly Palindromic Number problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.

Table of Contents

  1. Problem Statement
  2. Complexity Analysis
  3. Strictly Palindromic Number solution in C++
  4. Strictly Palindromic Number solution in Java
  5. Strictly Palindromic Number solution in Python
  6. Additional Resources
2396. Strictly Palindromic Number LeetCode Solution image

Problem Statement of Strictly Palindromic Number

An integer n is strictly palindromic if, for every base b between 2 and n – 2 (inclusive), the string representation of the integer n in base b is palindromic.
Given an integer n, return true if n is strictly palindromic and false otherwise.
A string is palindromic if it reads the same forward and backward.

Example 1:

Input: n = 9
Output: false
Explanation: In base 2: 9 = 1001 (base 2), which is palindromic.
In base 3: 9 = 100 (base 3), which is not palindromic.
Therefore, 9 is not strictly palindromic so we return false.
Note that in bases 4, 5, 6, and 7, n = 9 is also not palindromic.

Example 2:

Input: n = 4
Output: false
Explanation: We only consider base 2: 4 = 100 (base 2), which is not palindromic.
Therefore, we return false.

Constraints:

4 <= n <= 105

Complexity Analysis

  • Time Complexity: O(1)
  • Space Complexity: O(1)

2396. Strictly Palindromic Number LeetCode Solution in C++

class Solution {
 public:
  bool isStrictlyPalindromic(int n) {
    return false;
  }
};
/* code provided by PROGIEZ */

2396. Strictly Palindromic Number LeetCode Solution in Java

class Solution {
  public boolean isStrictlyPalindromic(int n) {
    return false;
  }
}
// code provided by PROGIEZ

2396. Strictly Palindromic Number LeetCode Solution in Python

class Solution:
  def isStrictlyPalindromic(self, n: int) -> bool:
    return False
# code by PROGIEZ

Additional Resources

See also  2424. Longest Uploaded Prefix LeetCode Solution

Happy Coding! Keep following PROGIEZ for more updates and solutions.