Programming Articles

Page 1176 of 2547

Find M-th number whose repeated sum of digits of a number is N in C++

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

In this problem, we are given two positive numbers N and M. Our task is to find the M-th number whose repeated sum of digits of a number is N. Problem description: Here, we need to find the Mth number whose sum of digits till the sum becomes single digit is equal to N.Let’s take an example to understand the problem,  Input: N = 4 M = 6Output: 49Solution ApproachA simple solution of the problem, is by finding all numbers and count the number whose sum of digits is N, and return m-th number.Another solution to the problem is using formula to find M-th ...

Read More

Find m-th smallest value in k sorted arrays in C++

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

In this problem, we are given k different arrays of different sizes. Our task is to find m-th smallest value in k sorted arrays. Problem Description: Here, we need to find m-th smallest element of the merged array of all k arrays.Let’s take an example to understand the problem,  Input:         m = 4                   arr[][] = { {4 , 7},                                     {2, 5, 6},                       ...

Read More

Find m-th summation of first n natural numbers in C++

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

In this problem, we are given two integers m and n. Our task is to Find m-th summation of the first n natural numbers. Problem Description: we will find sum of sum of n natural numbers m times. The sum is given by the formula, if (m > 1),           sum(n, m) = sum( sum(n, (m-1)), 1 )if (m = 1)          sum(n, m) = sum(n, 1) = sum of n natural numbersLet’s take an example to understand the problem,  Input: m = 4, n = 2Output: 231Explanation: sum(2, 4)     = sum ( sum(2, 3), 1 ...

Read More

Find max of two Rational numbers in C++

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

In this problem, we are given two Rational Numbers. Our task is to find max of two Rational numbers. Here, the rational numbers are in the form of p/q.Let’s take an example to understand the problem,  Input: rat1 = 5/4, rat2 = 3/2Output: 3/2Explanation: 5/4 = 1.253/2 = 1.5Solution Approach −A simple solution to the problem is by using a method similar to the one we used to perform in school.For this, we will find the L.C.M of the denominator. And then multiply the numerator based on the denominators value. Then for the common denominator, the rational number with maximum numerator value is the ...

Read More

Find maximum (or minimum) in Binary Tree in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 1K+ Views

In this problem, we are given a binary tree. Our task is to Find maximum (or minimum) in Binary Tree. Problem Description: We need to find the nodes of the binary tree that have maximum and minimum value in the binary tree.Let’s take an example to understand the problem,  Input: Output: max = 9 , min = 1Solution ApproachWe need to find the max node of the binary tree. We will do this by traversing the pointer until we reach the leaf node and then find the maximum node of the tree.Program to illustrate the working of our solution, Example#include using namespace std; ...

Read More

Find maximum (or minimum) sum of a subarray of size k in C++

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

In this problem, we are given an  array arr[] and a number k. Our task is to Find the maximum (or minimum) sum of a subarray of size k. Let’s take an example to understand the problem,  Input: arr[] = {55, 43, 12, 76, 89, 25, 99} , k = 2Output: 165Explanation:The subarray of size 2 has sum = 76 + 89 = 165Solution ApproachA simple approach to solve the problem is by finding all k sized subarrays and then return the sum with maximum value.Another Approach is using the sliding window,  we will find the sum of k sized subarrayes. For this, the ...

Read More

Find maximum among all right nodes in Binary Tree in C++

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

In this problem, we are given a Binary Tree. Our task is to find maximum among all right nodes in Binary Tree. Problem Description: Here, we need to find the maximum value amongst all right child nodes of the binary Tree.Let’s take an example to understand the problem,  Input: Output: 9Explanation: All right nodes are: {2, 8, 9}. Maximum of them is 9.Solution ApproachTo solve the problem, we need to traverse the tree and check if its right child exists. If it exists, compare with maxRight element and replace if it is greater.Program to illustrate the working of our solution, Example#include using namespace std; ...

Read More

Can we define an enum inside a class in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 17K+ Views

Enumerations in Java represents a group of named constants, you can create an enumeration using the following syntaxenum Days {    SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }Yes, we can define an enumeration inside a class. You can retrieve the values in an enumeration using the values() method.Examplepublic class EnumerationExample {    enum Enum {       Mango, Banana, Orange, Grapes, Thursday, Apple    }    public static void main(String args[]) {       Enum constants[] = Enum.values();       System.out.println("Value of constants: ");         for(Enum d: constants) {          System.out.println(d); ...

Read More

How to get the list of available data frames in R environment?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 2K+ Views

When we perform any type of data analysis, there are many types of objects that are created in the R environment such as vector, data frame, matrix, lists, arrays, etc. If we want to get the list of available data frames in R environment then we can use the below command −names(which(unlist(eapply(.GlobalEnv,is.data.frame))))Examplex1

Read More

Find maximum among x^(y^2) or y^(x^2) where x and y are given in C++

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

In this problem, we are given two values x and y. Our task is to find maximum among x^(y^2) or y^(x^2) where x and y are given. Let’s take an example to understand the problem,  Input: x = 4, y = 3Output: 3^(4^2)Explanation: x^(y^2) = 4^(3^2) = 4^9 = 262144y^(x^2) = 3^(4^2) = 3^16 = 43046721Solution approachOne approach can be to calculate both values and then print the maximum of both. But this method does not work when the values are large.A simple and easy approach is using natural log (ln) which will be the solution easier.ln(x^(y^2)) = (y^2) * ln(x)ln(y^(x^2)) = (x^2) * ...

Read More
Showing 11751–11760 of 25,466 articles
Advertisements