Server Side Programming Articles - Page 1929 of 2646

Print all nodes that are at distance k from a leaf node in C++

sudhir sharma
Updated on 22-Jan-2020 10:06:10

240 Views

In this problem, we are given a binary tree and a number K. We have to print all nodes of the tree that are at k distance from the leaf node.Binary Tree is a special tree whose each node has at max two nodes (one/two/none).The leaf node of a binary tree is the node at end of the tree.In this problem, distance from the leaf node is the node at a higher level than the leaf node. Suppose, the node at distance 2 from the leaf node at level 4 will be at level 2.Let’s take an example to understand ... Read More

Print all numbers less than N with at-most 2 unique digits in C++

sudhir sharma
Updated on 22-Jan-2020 10:00:06

202 Views

In this problem, we are given an integer N and we have printed all the number less than N with at-most 2 unique digits i.e. maximum 2 different digits can be used to create the number.Let’s take an example to understand the problem −Input: N = 17 Output: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16To solve this problem, we will be generating all numbers that have only two unique digits. Our number generating process starts from 0 and ends when our number is equal to or greater than N. For two ... Read More

Print all numbers whose set of prime factors is a subset of the set of the prime factors of X in C++

sudhir sharma
Updated on 22-Jan-2020 09:55:23

254 Views

In this problem, we are given a set of N numbers and a number X. And we have to print all numbers from the array whose set of prime factors is a subset of the set of prime factors of X.Let’s take an example to understand the problemInput: X= 30 , array = {2, 3, 6, 10, 12} Output : 2 3 6To solve this problem, we have to traverse elements of the array. And divide this element with gcd of (element, x). Repeat division till the gcd becomes 1. And print the remaining number.Example Live Demo#include using namespace std; ... Read More

Print all odd nodes of Binary Search Tree in C++

Farhan Muhamed
Updated on 18-Aug-2025 11:30:02

335 Views

A Binary Search Tree is a data structure that stores data in a sorted order such that for every node, the left subtree contains values less than the node's value, and the right subtree contains values greater than the node's value. In this article, we will solve the problem of finding all odd nodes of a binary search tree in C++. Find Odd-Valued Nodes in BST You are given a binary search tree (BST) as input and your task is to write a program that finds all the nodes with odd values and returns them as output. To understand ... Read More

Print all pairs in an unsorted array with equal sum in C++

sudhir sharma
Updated on 22-Jan-2020 09:42:05

341 Views

In this problem, we have an unsorted array and we have to print all pairs within this array that have an equal sum.Let’s take an example to understand the problem −Input: array = [12, 13, 20, 5] Output: [12, 13] and [20, 5] have sum 25.To solve this problem, we will have to find pairs of the same sum. For this, we will check pairs for the same sum. And to avoid duplicate pairs, we will use the map.For this, we will need two maps, one to store all sum pairs and their sum and others to store all sum ... Read More

Print all pairs of anagrams in a given array of strings in C++

sudhir sharma
Updated on 22-Jan-2020 09:37:31

496 Views

In this problem, we are given an array of strings and we have to print all pairs of anagrams of that given array.Anagrams are strings that are formed by rearranging the character of another string. Like − hello and lolheLet’s take an example to understand the problem −Input: array = {“hello”, “hrdef”, “from”, “lohel”, “morf”}. Output: [hello, lohel] , [from , morf]To solve this problem, we will use the nesting of loops. We need two nested loops, the outer loop will traverse over the array and select elements. The nested loop will check each of the string and check if ... Read More

Migrating PHP 5.x to PHP 7 on CentOS 7

Samual Sam
Updated on 22-Jan-2020 08:14:19

518 Views

In this article, we will learn about how to upgrade and update PHP 5.x to PHP 7, PHP 7 which was released in 2015 with speed improvements comparable to the older versions of the PHP.PrerequisitesAssuming that we have already installed PHP 5.x on CentOS7, and mod_php module should be enabled by Apache, and we need Sudo privileges or root user.Enabling the PHP 7 RepositoryAs PHP 7.x is not available in the official repositories, so we need to use IUS community Project Repository.Download the IUS repository in the machine with the below command# curl 'https://setup.ius.io/' -o setup-ius.sh curl 'https://setup.ius.io/' -o setup-ius.sh ... Read More

Convert time from 24 hour clock to 12 hour clock format in C++

Ayush Gupta
Updated on 22-Jan-2020 07:49:52

944 Views

In this tutorial, we will be discussing a program to convert time from 24 hour clock to 12 hour clock format.For this we will be provided with certain time in 24 hour format. Our task is to convert it into 12 hour format with the extension of “AM” or “PM”.Example Live Demo#include using namespace std; //converting into 12 hour format void convert_12hour(string str){    int h1 = (int)str[0] - '0';    int h2 = (int)str[1] - '0';    int hh = h1 * 10 + h2;    //finding the extension    string Meridien;    if (hh < 12) {       Meridien = "AM";    }    else       Meridien = "PM";       hh %= 12;    if (hh == 0) {       cout

Convert the undirected graph into directed graph such that there is no path of length greater than 1 in C++

Ayush Gupta
Updated on 22-Jan-2020 07:45:37

226 Views

In this tutorial, we will be discussing a program to convert the undirected graph into a directed graph such that there is no path of length greater than 1.For this we will be provided with an undirected graph. Our task is to convert that graph into a direct one given no path has a length greater than 1.Example Live Demo#include using namespace std; #define N 100005 //storing the graph vector gr[N]; //storing colour of each vertex int colour[N]; vector edges; bool bip; //adding edges to the graph void add_edge(int x, int y){    gr[x].push_back(y);    gr[y].push_back(x);    edges.push_back(make_pair(x, y)); } ... Read More

Convert the string into palindrome string by changing only one character in C++

Ayush Gupta
Updated on 22-Jan-2020 07:42:15

413 Views

In this tutorial, we will be discussing a program to convert the string into palindrome string by changing only one character.For this we will be provided with a string. Our task is to convert the given string into a palindrome by changing only one character.Example Live Demo#include using namespace std; //checking if conversion to palindrome //is possible bool if_palindrome(string str){    int n = str.length();    //counting number of characters    //to be changed    int count = 0;    for (int i = 0; i < n/2; ++i)       if (str[i] != str[n - i - 1])          ++count;    return (count

Advertisements