Sort by

recency

|

1738 Discussions

|

  • + 0 comments

    Here is my c# solution, i didnt use array to reverse

        public static int beautifulDays(int i, int j, int k)
        {
            int reverse = 0,day = 0;
            for(int num=i ; num <= j ; num++){
                int temp = num;
                while(temp > 0){
                    reverse = reverse * 10 + temp % 10;
                    temp /= 10;
                }
                int diff = Math.Abs(num - reverse);
                if(diff%k == 0){
                    day++;
                }
                reverse = 0;
            }
            return day;
        }
    
  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/6rYwcW6BYH4

    int beautifulDays(int i, int j, int k) {
        int ans = 0;
        for(int el = i; el <= j; el++){
            string s = to_string(el);
            reverse(s.begin(), s.end());
            if(abs(stoi(s) -el ) % k == 0) ans++;
        }
        return ans;
    }
    
  • + 0 comments
    def beautifulDays(i, j, k):
        count=0
        for day in range(i,j+1):
            if (abs(day-int(str(day)[::-1])))%k==0:
                count+=1
        return count
    

    or

    return sum([1 if (abs(day-int(str(day)[::-1])))%k==0 else 0 for day in range(i,j+1)])
    
  • + 0 comments

    ** Python solution in 1 line **

    def beautifulDays(i, j, k): return sum([abs(num - int(str(num)[::-1]))%k==0 for num in range(i, j+1)])

  • + 0 comments

    My Entry:

    return len([x for x in range(i, j+1) if abs(x - int(str(x)[::-1]))/k % 1 == 0])