Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 1321 of 3366
165 Views
In this problem, we are given two integer values N and X. Our task is to create a program to Find Nth positive number whose digital root is X.Digital Root (X) is a single digit positive number which is found by adding digits of N recursively adding digits, till the sum becomes single digit.Let’s take an example to understand the problem, InputN = 5, X = 4Output40Solution ApproachA simple way to solve the problem is by counting the numbers with a digital root is X. For this, we will start from 1 and then check if the current number’s digital ... Read More
295 Views
In this problem, we are given an integer value N. Our task is to create a program to Find Nth number of the series 1, 6, 15, 28, 45, …In the series, every element is 2 less than the mean of the previous and next element.Let’s take an example to understand the problem, InputN = 5Output45Solution ApproachThe Nth term of the series 1, 6, 15, 28, 45, … can be found using the formula, TN = 2*N*N - NProgram to illustrate the working of our solution, Example Live Demo#include using namespace std; #define mod 1000000009 int calcNthTerm(long n) { ... Read More
147 Views
In this problem, we are given an integer value N. Our task is to create a program to Find nth Hermite number.Hermite Number is a number is the value of hermite number when there are 0 arguments.Nth hermite Number is HN = (-2) * (N - 1) * H(N-2) The base values are H0 = 1 and H0 = 0.The hermite sequence is − 1, 0, -2, 0, 12, 0, -120, 0, 1680, 0….Let’s take an example to understand the problem, InputN = 7Output0InputN = 6Output-120Solution ApproachA simple solution to the problem is using the formula for hermite number. This ... Read More
371 Views
In this problem, we are given an integer value N. our task is to create a program to find the next spares Number.Sparse Number is a special type of number whose binary conversion does not contain any adjacent 1’s.Example: 5(101) , 16(10000)Problem Description − For the given number N, we need to find the smallest number greater than N which is a sparse number.Let’s take an example to understand the problem, InputN = 7Output8ExplanationThe binary of 8 is 1000 which makes it the smallest sparse number greater than n.Solution ApproachA simple solution to the problem is checking for all numbers ... Read More
380 Views
In this problem, we are given an array arr[] consisting of n integer values. Our task is to Find the next Smaller of the next Greater in an array.Problem Description − We will find an element greater than the current element in the array and then we will be finding the element in the array which is smaller than this greater element. And if no next smaller or next greater element exists in the array return -1.Let’s take an example to understand the problem, Inputarr[] = {4, 2, 8, 3, 9, 1}Output{3, 3, 1, 1, -1, -1}ExplanationArray of next greater ... Read More
262 Views
In this problem, we are given a binary Tree BT and a key value. Our task is to Find next right node of a given key.Binary Tree is a special data structure used for data storage purposes.Let’s take an example to understand the problem, Inputkey = 4Output5ExplanationThe element next to the node 4 is 5.Solution ApproachA simple solution to the problem is by traversing the binary tree using the level order traversal. And for the given key value, we will check if there exists an node next to node at the same level in the traversal. If Yes, return the ... Read More
287 Views
In this problem, we are given an element N. We need to find the next palindrome prime.Problem Description − We need to find the smallest prime number which is also a palindrome number, greater than N.Palindrome Number is a number in which the numbers are the same in both directions.Prime Number is a number if its only factors are 1 and itself.Let’s take an example to understand the problem, InputN = 12Output101ExplanationThe series of palindromes greater than 12 are 22, 33, 44, 55, 66, 77, 88, 99, 101… out of these the smallest palindrome is 101.Solution ApproachA simple solution to ... Read More
1K+ Views
In this problem, we are given an element N. We need to find the next greater number with the same set of digits. We need to find the smallest number with the same digit which is greater than N.Let’s take an example to understand the problem, InputN = "92534"Output92543Solution ApproachA simple solution to the problem to find the next greater element is by the following approach −Traverse the number from least significant bit to most significant bit. And stop when the current element is smaller than the last element.After this search for the smallest element in the remaining array. And ... Read More
2K+ Views
In this problem, we are given an element N. we need to find the N’th number in a number system with only 3 and 4.The number system consists of elements 3, 4, 33, 34, 43, 44, 333, 334, 343, 344, …Let’s take an example to understand the problem, InputN = 6Output44ExplanationThe numbers of the number system are − 3, 4, 33, 34, 43, 44...Solution ApproachThe number system is similar to the binary number system but the number 0 is replaced by 3 and number 1 is replaced by 4.Let’s say this as sBinary.So, number Nth number is (n-1)’s Sbinary conversion.With ... Read More
200 Views
In this problem, we are given two sorted arrays arr1[] and arr2[] of size m and an element N. Our task is to Find Nth item in a set formed by the sum of two arrays.Code description − Here, we will create a set that consists of the sum of element one of arr1 and one of arr2 i.e. sum = arr1[i] + arr2[j], where are i , j < m. For N, we need to find the value of the Nth element of the set.Let’s take an example to understand the problem, Inputarr1[] = {3, 1, 5} , arr2[] = ... Read More