hi, let Avik connect you.


** You can give your thought about this content and request modifications if needed from Ask For Modifications page. Thank You.

** You can check all the posts on the Posts page.

** More about me in the About Me section.

Confusing Number


  • Approach:

    • Reverse the number.

    • If any of 2, 3, 4, 5, or 7 are encountered then return False.

    • If 6 is encountered make the reversed digit 9.

    • If 9 is encountered make the reversed digit 6.

    • Return true if the original number and the reversed number are not equal. Else return False.


  • Time and Space Complexity:

      • Time Complexity: O(length of digit in N)

      • Space Complexity: O(1)


Code [C++]

bool confusingNumber(int N){

int reversed = 0, tempN = N;

while(N){

int rem = N % 10;

if(rem == 2 || rem==3 || rem==4 || rem==5 || rem == 7) return false;

if(rem == 9) rem = 6;

if(rem == 6) rem = 9;

reversed *= 10;

reversed += rem;

N /= 10;

}

return (reversed != tempN);

}