Given two positive integers N and S. The task is to minimize the number of increments on N (N = N + 1) required to make the sum of digits of N less than or equal to S. NOTE: N can range up to an18 digit number and 1

Continue ReadingGiven 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 ReadingGiven a range from L to R and an integer K, the task is to count the number of integers in the given range such that their last K digits are equal.Example: Input: L = 49, R = 101, K=2Output: 6Explanation: There are 6 possible integers t.e., 55, 66, 77, 88, 99 and 100 such that […]

Continue ReadingGiven a string S consisting of N digits and an integer K, the task is to count the number of ways to remove digits from the number formed by the concatenating the string S, K number of times, such that the resulting string is divisible by 5. Since count can be very large, so print […]

Continue ReadingGiven a string str[] number N, the task is to calculate the number of ways to make the given number divisible by 3 by changing at most one digit of the number.Examples:Input: str[] = “23”Output: 7Explanation: Below are the numbers that can be made from the string which are divisible by 3 – 03, 21, […]

Continue ReadingGiven a positive integer N, the task is to count the number of N-digit numbers such that every index (1-based indexing) in the number is divisible by the digit occurring at that index. Since the court can be very large, print it modulo 109 + 7.Examples:Input: N = 2Output: 2Explanation: The numbers 11 and 12 […]

Continue ReadingGiven a binary string S, the task is to find that the decimal representation of the given binary string is divisible by integer K or not.Examples:Input: S = 1010, k = 5Output: YesExplanation: Decimal representation of 1010 (=10) is divisible by 5Input: S = 1010, k = 6Output: NoApproach: Since the modulo operator is distributive […]

Continue Readingimport 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 ReadingCount N-digit numbers that contains every possible digit atleast onceGiven a positive integer N, the task is to count the number of N-digit numbers such that every digit from [0-9] occurs at least once. Examples : Input: N = 10Output : 3265920Input: N = 5Output: 0Explanation: Since the number of digits is less than the minimum number […]

Continue ReadingCheck if sum of digits in the left half is divisible by sum of digits in the right half in the largest permutation of NGiven a positive integer N, the task is to maximize the integer N by rearranging the digits and check if the sum of the left half digits is divisible by the […]

Continue Reading