Category: number-digits

Check if all the digits of the given number are same

Given a positive integer N, the task is to check whether all the digits of the given integer N are the same or not. If found to be true, then print Yes. Otherwise, print No.Examples:Input: N = 222Output: YesInput: N = 232Output: NoNaive Approach: The simplest approach to solve the given problem is to iterate […]

Continue Reading

Count of N-digit numbers having each digit as the mean of its adjacent digits

import java.util.*;  class GFG{static int dp[][][] = new int[100][10][10];static int countOfNumbers(int digit, int prev1,                   int prev2, int n){            if (digit == n + 1) {        return 1;    }            int val = dp[digit][prev1][prev2];    if (val != -1) {        return val;    }    val = 0;                    if (digit == 1) {        for (int i = (n == 1 ? 0 : 1); i

Continue Reading