Server Side Programming Articles

Page 1196 of 2109

Check if it is possible to return to the starting position after moving in the given directions in C++

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

Suppose we are at position (0, 0) We have a string represents consecutive directions using four letters. We have to check whether we can return at (0, 0) position after considering all of the given directions. The symbols areE for eastW for westN for northS for south.So, if the input is like "EENWWS", then the output will be true, move east two units, then go north, then west two units then again south, so this is the starting position.To solve this, we will follow these steps −l := size of moves arrayif l is same as 0, then −return truelft ...

Read More

Elements of an array that are not divisible by any element of another array in C++

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

In this problem, we are given two arrays arr1[] and arr2[]. Our task is to create a program to find the elements of an array that are not divisible by any element of another array. Problem Description: Here, we need to find all elements from arr1 that are not divisible by any elements of arr2.Let’s take an example to understand the problem, Input: arr1[] = {17, 15, 5, 12, 8}        arr2[] = {5, 4}Output: 17Explanation −Elements of arr1 and elements dividing them, 17 -> no element can divide it.15 -> 5 divides the element.5 -> 5 divides the element.12 -> 4 ...

Read More

Elo Rating Algorithm in C++

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

Elo Rating Algorithm is a rating algorithm used to rank players in competitive games. The ranking of player of the competition is based on ranting which changes based on the performance of the player as follows, For a game between two players of different ratings. Let’s say there are two players competing against each other−Player1                          Player2Rating of player1 is greater than player2.If player1 wins the game some player will be transferred from player1 to player2 and vice versa if player2 wins.But the amount of rating to be transferred for victory ...

Read More

Enumeration of Binary Trees in C++

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

Enumeration of Binary Tree is counting the total number of distinct unlabeled binary trees of a given size (specific number of nodes). In this article, we will create a program to count the number of Binary Trees of n nodes.Based on labeling of nodes of binary tree, it is of two types:Labeled Binary TreeUnlabeled Binary TreeLabeled Binary Tree: It is a binary Tree in which the nodes of a tree are labeled with values.Different Type of Labeled Binary Tree for a given number of nodes :Number of nodes N = 2Similarly, We can find the number of distinct labeled binary Tree for ...

Read More

Equidigital Numbers in C++

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

Equidigital numbers are mathematically special numbers in which the number of digits in the number is equal to the number in its prime factorization.In this problem, we are given an integer value n. Our task is to create a program to all equidigital numbers up to n.Let’s take an example to understand the problem, Input: n =  12Output:  1 2 3 5 7 10 11Solution Approach:A simple solution to the problem would be finding the factors of the number and check if the number of primes is equal to the number of digits in the number .The prime factors can be ...

Read More

Evaluation of Prefix Expressions in C++

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

In this article, we will discuss the evaluation of prefix Expression. Prefix ExpressionIn this notation, operator is prefixed to operands, i.e. operator is written ahead of operands. For example, +ab. This is equivalent to its infix notation a + b. Prefix notation is also known as Polish Notation.For more read.Example:* + 6 9 - 3 1Prefix expressions are evaluated faster than infix expressions. Also, there are no brackets in prefix expressions which make it evaluate quicker.Algorithm to evaluate Prefix Expression:The evaluation of prefix expression requires a stack data structure. We will push the operators in the stack and then solve the ...

Read More

Evaluation of Expression Tree in C++

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

In this problem, we are given an expression tree that consist of binary operations like +, - , /, *. We need to do the evaluation of the expression tree and then return the result.Expression Tree is a special type of binary tree in which each node either consist of an operator or operand which are distributed as−Leaf nodes of the tree are values on which the operation is to be performed. Non-leaf nodes consist of the binary operator denoting the operation to be performed. Let’s take an example to understand the problem, Input: Output: 1Explanation: Decoding the expression tree, Exp           ...

Read More

Extended Midy's theorem in C++

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

Midy’s Theorem is a statement used for decimal expansion of numbers denoted by n/p, where n is any number and p is a prime number and a/p has a repeating decimal with even period.In Extended Midy’s Theorem, the repeating portion is divided into m digits, then their sum is a multiple of 10m - 1. Program to illustrate Extended Midy’s Theorem: Example#include using namespace std; string findDecimalValue(int num, int den) {        string res;    unordered_map mp;    int rem = num % den;    while ((rem != 0) && (mp.find(rem) == mp.end())) {     ...

Read More

Fermat's Last Theorem in C++

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

Fermat’s last theorem in number theory also known as Fermet’s conjecture is a theorem that states that for power n greater than 2. No three values a, b, c satisfy −          an + bn = cni.e.     if n 32 + 42 = 9 + 16 = 25 = 52. 5, 12, 13 => 25 + 49 = 169 = 132.In this problem, we are given three values, L, R, pow denoting range [L, R] and power. Our task is to verify the fermat’s last theorem for the given range and power.Let’s take an example to understand the problem, ...

Read More

Fifth root of a number in C++

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

In this problem, we are given a number N. Our task is to find the floor value of the fifth root of a number.Fifth Root of a number is the number which when multiplied to itself 5 times returns the number.If N1/5 = a then, a*a*a*a*a = N.Let’s take an example to understand the problem, Input: N = 325Output: 3Explanation:  The fifth root of 325 is 3.179 whose floor value is 3.Solution Approach: A simple solution to the problem is traversing from 1 to n. And finding the number which when multiplied to itself five times gives the number.Here, the exact value cannot be found ...

Read More
Showing 11951–11960 of 21,090 articles
Advertisements