Programming Articles

Page 221 of 2545

Count of all possible values of X such that A % X = B in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 275 Views

Given two integers A and B and a number X. The goal is to find the count of values that X can have so that A%X=B. For the above equation if, A==B then infinite values of X are possible, so return −1. If A < B then there would be no solution so return 0. If A>B then return count of divisors of (AB) as result.For ExampleInputA=5, B=2OutputCount of all possible values of X such that A % X = B are: 1Explanation5%3=2. So X is 3 here.InputA=10, B=10OutputCount of all possible values of X such that A % X ...

Read More

Find kth node from Middle towards Head of a Linked List in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 511 Views

In this problem, we are given a linked-list and a number k. Our task is to find kth node from Middle towards the Head of a Linked List. Let’s take an example to understand the problem,  Input: linked-list : 4 -> 2 -> 7 -> 1 -> 9 -> 12 -> 8 -> 10 -> 5, k = 2Output: 7Explanation: Middle node value is 9.The 2nd node from middle towards head is 7.Solution ApproachWe need to find kth element from the middle of the linked-list towards the beginning. For this we need to find the size of linked-list by traversing the linked-list from beginning ...

Read More

Program to Reverse a Substring Enclosed Within Brackets in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 567 Views

Suppose, we have a lowercase string s that contains letters and parentheses "(" and ")". We have to reverse every string enclosed within parentheses in a recursive manner and return the resultant string.So, if the input is like s = "back(aps)ce", then the output will be “backspace”.To solve this, we will follow these steps −Define a function trav() . This will take s, dir, start, close:= close, ans:= ansend := "(" if dir is same as −1, otherwise ")"other := "(" if end is same as ")", otherwise ")"while start < size of s, and s[start] is not same as ...

Read More

Count of all N digit numbers such that num + Rev(num) = 10^N - 1 in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 195 Views

Given a number N as input. The goal is to find the count of all N digit numbers that have sum Count of all N digit numbers such that num + Rev(num) = 10N − 1num+rev(num)=10N−1For ExampleInputN=4OutputCount of all N digit numbers such that num + Rev(num) = 10N − 1 are − 90ExplanationThe numbers would be − 1. 1188 + 8811 = 9999 2. 2277 + 7722 = 9999 3. 1278 + 8721 = 9999 ……...total 90 numbersInputN=5OutputCount of all N digit numbers such that num + Rev(num) = 10N − 1 are − 0ExplanationAs N is odd, ...

Read More

Check if is possible to get given sum from a given set of elements in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 499 Views

Suppose we have an array called nums and another value sum. We have to check whether it is possible to get sum by adding elements present in nums, we may pick a single element multiple times.So, if the input is like nums = [2, 3, 5] sum = 28, then the output will be True as we can get 26 by using 5 + 5 + 5 + 5 + 3 + 3 + 2To solve this, we will follow these steps −MAX := 1000table := an array of size MAX ad fill with 0Define a function util() . This ...

Read More

Find kth smallest number in range [1, n] when all the odd numbers are deleted in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 222 Views

In this problem, we are given two integer values n and k. Our task is to find kth smallest number in range [1, n] when all the odd numbers are deleted. We need to find the kth smallest number in the range [1, n] which contains only even values.So, from range [1, 5] -> number will be 2, 4.Let’s take an example to understand the problem,  Input: n = 12, k = 4Output: 8Explanation: Even elements in the range [1, n] : 2, 4, 6, 8, 10, 12The 4th smallest element is 8.Solution approach: The solution is simple as we need to find the kth ...

Read More

Program to Find Out Integers Less than n Containing Multiple Similar Digits in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 257 Views

Suppose we have an integer n, we have to find the number of positive integers that are less than or equal to n, where the integer numbers at least have a digit occurring more than once.So, if the input is like n = 200, then the output will be 38To solve this, we will follow these steps −Define an array afor initialize x := n, when x is non−zero, update x := x / 10, do −insert x mod 10 at the end of areverse the array aret := nfor initialize w := 1, d := 1, when w < ...

Read More

Count of arrays in which all adjacent elements are such that one of them divide the another in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 457 Views

Given two integers named ‘one’ and ‘another’. The goal is to find the number of possible arrays such that −The elements in the array are in range between 1 and ‘another’.All elements of array are such that arr[i] divides arr[i+1] or arr[i+1] divides arr[i+2]....and so on.The length of the array is ‘one’.For ExampleInputone = 3, another = 2OutputCount of arrays in which all adjacent elements are such that one of them divide the another are: 8ExplanationThe arrays will be: [ 1, 1, 1 ], [ 1, 1, 2 ], [ 1, 2, 1 ], [ 1, 2, 2 ], [ ...

Read More

Check if it is possible to convert one string into another with given constraints in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 245 Views

Suppose we have two strings s and t with only three characters 'A', 'B' and '#'. We have to check whether it is possible to convert s into t by performing these operations on s.'A' can move only to the left hand side'B' can move only to the right hand sideNeither 'A' nor 'B' can cross each otherSo, if the input is like s = "##AB##B" t = "A###B#B", then the output will be True as in s A can move easily to the left most position, and middle B can move one step to the rightTo solve this, we ...

Read More

Find larger of x^y and y^x in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 248 Views

In this problem, we are given two numbers x and y. Our task is to find larger of x^y and y^x. Problem Description: The problem is simple, we need to find weather x to the power y is greater than y to the power x.Let’s take an example to understand the problem,  Input: x = 4, y = 5Output: 1024Explanation: x^y = 4^5 = 1024y^x = 5^4 = 625Solution ApproachThe solution to the problem is simple. We need to find the value of x^y and y^x and return the maximum of both.There can be a more mathematically easy way to solve the problem, which is ...

Read More
Showing 2201–2210 of 25,445 articles
« Prev 1 219 220 221 222 223 2545 Next »
Advertisements