Join Regular Classroom : Visit ClassroomTech

Hackwithinfy 2021 Solution | Special Numbers

Question: Special Numbers

Solution: In C

int specialNumbers(int L, int R)
{
        int ans = 0;

        if ( L < 369 && R >= 369)
                L = 369;

        while (L <= R)
        {
                int count3 = 0 , count6 = 0, count9 = 0;

                for(int i=L; i>0; i/=10)
                {
                        if ( i%10 == 3)
                                count3 ++;

                        else if (i%10 == 6)
                                count6 ++;

                        else if (i % 10 == 9)
                                count9 ++;

                }

                if (count3 > 0 && count3 == count6 && count3 == count9)
                        ans ++;

                L++;
        }

        return ans;

}