Found 33676 Articles for Programming

Find a pair with given sum in BST in C++

Hafeezul Kareem
Updated on 01-Feb-2021 11:58:31

212 Views

In this tutorial, we are going to write a program that finds the pair whose sum is equal to the given number in the binary search tree.We are going to store and values of trees in two different lists to find the pairs. Let's see the steps to solve the problem.Create a struct node for a binary tree.Write a function to insert a new node into the binary search tree.Remember, in the binary search tree all the elements that are less than root are smaller, and right are larger.Initialize two empty lists to store the left and right nodes of ... Read More

Find a Number X whose sum with its digits is equal to N in C++

Hafeezul Kareem
Updated on 01-Feb-2021 11:58:04

206 Views

In this tutorial, we are going to find a number whose some including with its digits is equal to the given number N.The idea is simple, we are going to check the left and right 100 numbers of the given number. It won't lie out that bound as N ≤ 1000000000 and the sum won't exceed 100.Let's see the steps to solve the problem.Initialize the number.Write a loop that iterates 100 times.Get the n - i and n + i values.Find the sum of the digits and add them.If anyone of them is equal to the N, print them.ExampleLet's see ... Read More

Find a number that divides maximum array elements in C++

Hafeezul Kareem
Updated on 01-Feb-2021 11:57:48

202 Views

In this tutorial, we are going to find the number that is divided into maximum elements in the given array.Let's see the steps to solve the problem.Initialize the array and a variable to store the result.Iterate over the array.Initialize the counter variable.Iterate over the array again.Increment the counter if the current element is divisible by the array element.Update the result if the current count is maximum.Print the result.ExampleLet's see the code. Live Demo#include using namespace std; int numberWithMaximumMultiples(int arr[], int n) {    int result = -1;    for (int i = 0; i < n; i++) {     ... Read More

Find (1^n + 2^n + 3^n + 4^n) mod 5 in C++

Hafeezul Kareem
Updated on 01-Feb-2021 11:47:43

252 Views

In this tutorial, we are going to solve the following problem.Given an integer n, we have to find the (1n+2n+3n+4n)%5The number (1n+2n+3n+4n) will be very large if n is large. It can't be fit in the long integers as well. So, we need to find an alternate solution.If you solve the equation for the number 1, 2, 3, 4, 5, 6, 7, 8, 9 you will get 10, 30, 100, 354, 1300, 4890, 18700, 72354, 282340 values respectively.Observe the results of the equation carefully. You will find that the last digit of the equation result repeats for every 4th number. ... Read More

Find 2^(2^A) % B in C++

Hafeezul Kareem
Updated on 01-Feb-2021 11:45:39

127 Views

In this tutorial, we are going to write a program to evaluate the equation 2^(2^A) % B.We are going to find the value of the equation using a recursive function. Let's see the steps to solve the problem.Write a recursive function that takes 2 arguments A and B.If A is 1, then return 4 % B as 2^(2^1) % B = 4 % B.Else recursively call the function with A-1 and b.Return the result^2%B.Print the solutionExampleLet's see the code. Live Demo#include using namespace std; long long solveTheEquation(long long A, long long B) {    // 2^(2^1) % B = 4 ... Read More

Find A and B from list of divisors in C++

Hafeezul Kareem
Updated on 01-Feb-2021 11:42:59

164 Views

In this tutorial, we are going to solve the below problem.Given an array of integers, we have to find two numbers A and B. All the remaining numbers in the array are the divisors of A and B.If a number is a divisor of both A and B, then it will present twice in the array.Let's see the steps to solve the problem.The max number in the array is one of the numbers from A and B. Let's say it is A.Now, B will be the second-largest number or the number which is not a divisor of A.ExampleLet's see the ... Read More

How to set window size using phantomjs and selenium webdriver in Python?

Debomita Bhattacharjee
Updated on 01-Feb-2021 11:46:54

329 Views

We can set window size using PhantomJS and Selenium webdriver in Python. To work with the PhantomJS, we should create a driver object of the webdriver.PhantomJS class.Then pass the path of the phantomjs.exe driver file as a parameter to the Class. Next, to set the window size, we shall use the set_window_size method and pass the dimensions as parameters to the method.To obtain the window size of the browser, we can use the get_window_size method.Syntaxdriver.set_window_size(800, 1000) print(driver.get_window_size())Examplefrom selenium import webdriver #set phantomjs.exe path driver = webdriver.PhantomJS(executable_path="C:\phantomjs.exe") driver.maximize_window() #launch URL driver.get("https://www.tutorialspoint.com/index.htm") #set new window size driver.set_window_size(800, 880) #obtain window size print(driver.get_window_size()) ... Read More

Find (a^b)%m where ‘a’ is very large in C++

Hafeezul Kareem
Updated on 01-Feb-2021 11:42:43

232 Views

In this tutorial, we are going to solve the equation (ab)%m where a is a very large number.The equation (ab)%m=(a%m)*(a%m)...b_times. We can solve the problem by finding the value of a%m and then multiplying it b times.Let's see the steps to solve the problem.Initialize the numbers a, b, and m.Write a function to find the a%m.Initialize the number with 0.Iterate over the number in string format.Add the last digits to the number.Update the number with number modulo them.Get the value of a%m.Write a loop that iterates b times.Multiply the a%m and modulo the result with m.Print the result.ExampleLet's see the ... Read More

Final string after performing given operations in C++

Hafeezul Kareem
Updated on 01-Feb-2021 11:42:25

209 Views

In this tutorial, we are going to solve the following problem.Given a string containing only characters a and b, our task is to delete the sub-string ab from the string. And print the remaining string.Here, the idea is very simple to solve the problem. Every string with only a's and b's will shrink to either a's or b's at the end.Let's see the steps to solve the problem.Initialize the string.Initialize two counter variables for a and b.Iterate over the given string.Count the a's and b'sFind the maximum from the a and b frequencies.Print the difference between the two.ExampleLet's see the ... Read More

Count of AP (Arithmetic Progression) Subsequences in an array in C++

Sunidhi Bansal
Updated on 29-Jan-2021 08:42:04

570 Views

Given an array arr[] containing integer elements. The goal is to count the number of Arithmetic Progression subsequences inside arr[]. The range of elements inside arr[] are [1, 1000000].Empty sequence or single element will also be counted.Let us understand with examples.For ExampleInput - arr[] = {1, 2, 3}Output - Count of AP (Arithmetic Progression) Subsequences in an array are: 8Explanation - The following subsequences will form AP:-{}, {1}, {2}, {3}, {1, 2}, {2, 3}, {1, 3}, {1, 2, 3}Input - arr[] = {2, 4, 5, 8}Output - Count of AP (Arithmetic Progression) Subsequences in an array are: 12Explanation - The following subsequences ... Read More

Advertisements