• + 0 comments

    another approach !

        if (i < 1 || j < 1 || k < 1) return -1;
    
        int count = 0;
    
        for (int n = i; n <= j; n++) {
            String wordInt = String.valueOf(n);
            int y = wordInt.length() - 1;
            String reverse = "";
    
            while (y >= 0) {
                reverse = reverse + wordInt.charAt(y);
                y--;
            }
    
            int num = Integer.parseInt(reverse);
            int difference = Math.abs(num - n);
    
            if (difference % k == 0) {
                count++;
            }
        }
        return count;