Palindrome in both Decimal and Binary | Practice | GeeksforGeeks

Given a number N. check whether a given number N  is palindrome or not in it's both formates (Decimal and Binary ).

Example 1:
Input: N = 7
Output: "Yes" 
Explanation: 7 is palindrome in it's decimal 
and also in it's binary (111).So answer is "Yes".

Example 2:
Input: N = 12
Output: "No"
Explanation: 12 is not palindrome in it's decimal
and also in it's binary (1100).So answer is "No". 



Your Task:  
You don't need to read input or print anything. Complete the function isDeciBinPalin() which takes N as input parameter and returns "Yes" if N is a palindrome in its both formates else returns "No".

Expected Time Complexity: O(logN)
Expected Auxiliary Space: O(1)

Constraints:
1<= N <=107
0
mail2rajab012 months ago
// Simple Java Solution
 
class Solution {   static boolean isPalindrome(String n){       String tmp=n;       String r="";       for(int i=n.length()-1;i>=0;i--){           r +=n.charAt(i);       }       if(r.equals(n)){           return true;       }       return false;   }   static String isDeciBinPalin(long N){       // code here       String tmp=Long.toBinaryString(N);       if(isPalindrome(Long.toString(N)) && isPalindrome(tmp)){           return "Yes";       }       return "No";          }}
0
rdm1233 months ago
def isDeciBinPalin (self, N):       k=str(N)[::-1]       m=bin(N)       m=m[2:]       if(str(N)==k and m==m[::-1]):           return "Yes"       return "No"
0
Kartik Tyagi11 months ago
Kartik Tyagi
python sol:Execution Time:0.03    def isDeciBinPalin (self, N):        num_str = str(N)        binn = bin(N)        binn = binn.replace("0b","")        if ((num_str[::-1] == num_str) and (binn[::-1] == binn)):            return "Yes"        else:            return "No"
0
NITIN SRIVASTAV1 year ago
NITIN SRIVASTAV
String str=String.valueOf(N);        String check="";        for(int i=str.length()-1;i>=0;i--){            check+=str.charAt(i);        }        String s=Long.toBinaryString(N);        String t="";        for(int i=s.length()-1;i>=0;i--){            t+=s.charAt(i);        }        if(check.compareToIgnoreCase(str) == 0 && t.compareToIgnoreCase(s)==0)           return "Yes";return "No";
0
SACHIN KUMAR1 year ago
SACHIN KUMAR
class Solution {    public:    string isDeciBinPalin(unsigned int  N){        vector<int>v;        while(N>0)        {            v.push_back(N%2);            N/=2;        }        int i=0,j=v.size()-1;        while(i<j) {="" if(v[i]!="v[j])" {="" return="" "no";="" }="" i++,j--;="" }="" return="" "yes";="" }="" };="">
0
This comment was deleted.
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.