Sort by

recency

|

1765 Discussions

|

  • + 0 comments

    For the python code

    def beautifulDays(i, j, k):
        # Write your code here
        reverse=0
        r=[]
        sub=0
        final=0
        for i in range(i,j+1):
            reverse=int(str(i)[::-1])
            sub=abs(i-reverse)
            if(sub%k==0):
                r.append(i)
        final=len(r)
        return final
    
  • + 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

    Idea reverse integer.

    1. Time Complexity: O(N)
    2. Space Complexity: O(1)
    int reverse_integer(int num){
        int res = 0;
        while (num != 0){
            int rem = num % 10;
            res = res*10+rem;
            num = num/10;
        }
        return res;
    }
    
    int beautifulDays(int i, int j, int k) {
        int res = 0;
        for (int num = i; num <= j; num++){
            int reversed_num = reverse_integer(num);
            int difference = abs(reversed_num-num);
            if (difference%k == 0){
                res ++;
            }
        }
        return res;
    }
    
  • + 0 comments

    Locksmith Training Bristol offers hands-on, expert-led courses that prepare you for a rewarding career in the locksmithing trade. From basic lock repairs to advanced security systems, this training equips you with real-world skills and confidence. Much like beautiful days at the movies bring excitement and lasting impressions, locksmithing delivers satisfaction through problem-solving and helping others. Start your journey today in Bristol and unlock new opportunities in a growing, essential industry.

  • + 0 comments

    My C++ solution:

    int reverse_digits(int number) {
        string num = to_string(number);
        reverse(num.begin(), num.end());
        return atoi(num.c_str());
    }
    
    int beautifulDays(int i, int j, int k) {
        int count = 0;
        for (int x=i; x<=j; x++) {
            int dividend = abs(x - reverse_digits(x));
            if (dividend % k == 0) {
                count++;
            }
        }
        return count;
    }