We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. All Contests
  2. ProjectEuler+
  3. Project Euler #145: How many reversible numbers are there below one-billion?
  4. Discussions

Project Euler #145: How many reversible numbers are there below one-billion?

Problem
Submissions
Leaderboard
Discussions

Sort 62 Discussions, By:

recency

Please Login in order to post a comment

  • nc1969
    6 months ago+ 0 comments

    For those who are struggling solving this. At one time it took me about a week of work to solve this problem, may be longer. This is no way an easy thing, and I doubt the solution can be written as one function. Particularly, me solution contains near 600 lines and 17 helper functions.

    0|
    Permalink
  • priyanshu_706811
    3 years ago+ 0 comments

    Time out can anyone fix it

    n = [int(input()) for i in range(0,int(input()))]
    def reverse(x):
        return int(str(x)[::-1])
    def isInputOdd(x):
        lis = str(x)
        for i in lis:
            if int(i)%2==0:
                flag = False
                return flag
            else:
                flag = True
        return flag
    def main(iter):    
        sum1=0
        for i in range(iter):
            k = i + reverse(i)
            if i%10!=0 and isInputOdd(k):
                sum1+=1
        print (sum1)
    for i in n:
        main(i)
    
    0|
    Permalink
  • 91_75isnotajoke
    4 years ago+ 2 comments

    Facing timeout problem... !! def procedure(n): s=str(n) #print("s = ",s) s1 = s[::-1] if int(s1)>10: #print("s1 = ",s1) #print(int(s1)) s2=n+int(s1) #print("s2 = ",s2) if '2' not in str(s2) and '4' not in str(s2) and'6' not in str(s2) and'8' not in str(s2) and'0' not in str(s2): return True else: return False

    t=int(input())#no of test cases while t>0: n=int(input()) c=0 for i in range(10,n): if procedure(i)==True: c=c+1

    print(c)
    t=t-1
    

    Time Complexity :--- O(no.of test cases* n).. Suggest me ...some alternatives.. !!

    0|
    Permalink
  • comp0zr
    4 years ago+ 0 comments

    After many, many, MANY attempts, I finally did it!

    0|
    Permalink
  • ameeralikhan
    6 years ago+ 0 comments

    now why time out i even reduced the complexity before by checking if either of first or last digit odd and even

    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include <stdlib.h>
    int isdigitsodd(unsigned long long num);
    int main() {
        unsigned long long number,reverse=0,sum=0,i,count=0,k,powervalue,logvalue,fd;
        int T,j,dig;
        scanf("%d",&T);
        for(j=1;j<=T;j++)
         {  count=0;
            scanf("%llu",&number);
            for(i=11;i<number;i++)
              {    k=i;reverse=0;
                   logvalue=log10(i);
                   powervalue=pow(10,logvalue);
                   fd=i/powervalue;
                   if(i%10==0)
                    { ;}
                   else if(((i%2)==0&&fd%2==1)||((i%2)==1&&fd%2==0))
                    {
                       while(k!=0)
                         {
                            dig=k%10;
                            reverse=reverse*10+dig;
                            k/=10;
                         }
                        sum=reverse+i;
                        if(isdigitsodd(sum)==1)
                           { count++;}
                       
                    } 
              }
            printf("%llu\n",count);
         }
        
        
        
        return 0;
    }
    int isdigitsodd(unsigned long long num)
    {
        int flag=0,dig=0;
        while(num!=0)
        {
           dig=num%10;
           if(dig%2==1)
              flag=1;
           else 
              {flag=0;break;}
           num/=10;
        }
        if(flag==1)
           return 1;
        else return 0;
    }
    
    0|
    Permalink
Load more conversations

Need Help?


View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy