In this tutorial, we are going to write a program that find the number of ways a integer can be expressed as sum of given n-th power of unique numbers.We have two integers number and power. And we need to find in how many ways can we represent the given number as sum of n-th power of unique natural numbers. Let's see an example.Input − number = 50, power = 2Output − 3There is only possible way we can write 4 as sum of 2 powers.We will be using recursion to solve the problem. Let's see the steps to solve ... Read More
In this tutorial, we are going to learn how to find the unique pairs that are less than the given number n.Let's see the steps to solve the problem.Initialize the number.Iterate from i = 1 to i < n.Iterate from j = i + 1 to j < n.Print the (i, j).ExampleLet's see the code. Live Demo#include using namespace std; void uniquePairs(int n) { for (int i = 1; i < n; ++i) { for (int j = i + 1; j < n; j++) { cout
In this tutorial, we are going to learn how to write a program for union and intersection of two unsorted arrays. Let's see an example.Input arr_one = [1, 2, 3, 4, 5] arr_two = [3, 4, 5, 6, 7]Output union: 1 2 3 4 5 6 7 intersection: 3 4 5Let's see the steps to solve the problem.UnionInitialize the two arrays with random values.Create an empty array called union_result.Iterate over the first array and add every element to it.Iterate over the section array and add element if it is not present in union_result array.Print the union_result array.IntersectionInitialize the two arrays with random ... Read More
In this tutorial, we are going to learn how to find distinct characters from the given two strings. Let's see an example.Input string_one = "tutorialspoint" string_two = "tutorialsworld"Outputd n p wWe are going to use hashing to solve the problem. It's more efficient than writing two nested loopLet's see the steps to solve the program.Initialize the two strings with some random values.Initialize a map as map chars.Iterate over the first string and insert each character into map with value 1.Now, iterate over the second string.Check whether the character is already present or not.If present, assign 0 to it.If not present insert ... Read More
In this tutorial, we are going to write a program to find two numbers where x + y = n and x * y = n. Sometimes it's not possible to find those types of numbers. We'll print None if there are no such numbers. Let's get started.The given numbers are the sum and products of a quadratic equation. So the number doesn't exist if n2 - 4*n
In this tutorial, we are going to write a program the find two distinct prime numbers with the given product. Let's see some examples.Input − 21Output − 3 7Here, we need to have all the prime numbers that are less than the given product. Once we have those prime numbers, then we can easily find the pair. Follow the below steps to solve the problem.Initialize a product and an boolean array to store whether a numbers in the range are prime or not.Find all the prime numbers that are less than given product and store them in a array.Iterate till ... Read More
In this tutorial, we are going to write a program that finds trace of matrix formed by row and column major matrices.Let's see how to form a row and column major matrices when order of the matrix is given.Order − 3 x 3Row Major Matrix −123456789Column Major Matrix −147258369We have row and column major matrices. Now, we have to add both the matrices. And the trace of the resultant matrix is the result that we are looking for.Let's see write the code to solve the problem. We have to complete the following 4 steps to finish the solution for the ... Read More
In this tutorial, we are going to write a program that computes the time taken for a signal to reach all positions in a string. Let me explain it with an example.We will have a string that contains only s and p characters. s is a signal and p is a position in the string. A signal starts at s and travels in both left and right directions. We are assuming it takes one unit of time to travel to the next position in the string. Our task is to compute the time needed to convert all positions into signals.Let's ... Read More
In this tutorial, we are going to write a program that is based on the concepts of LCM. As the title says, we have to find three numbers that are less than or equal to the given number whose LCM is maximum.Let's see an example.Before diving into the problem let's see what LCM is and write program for it.LCM is the least common multiple of a number. It is also known as Least common divisor. For two positive number a and b, the LCM is the smallest integer that is evenly divisible by both a and b.If the given integers ... Read More
We can perform Selenium testing without a browser. This is achieved by triggering the execution in a headless mode. The headless execution can decrease the utilization of key resources and is being adopted widely.For triggering headless execution in Chrome, the ChromeOptions class is utilized to modify the default browser characteristics. Headless is passed as a parameter to the addArguments.SyntaxChromeOptions opt = new ChromeOptions(); opt.addArguments("headless"); WebDriver d = new ChromeDriver(opt);ExampleCode Implementation.import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import java.util.concurrent.TimeUnit; public class WithoutBrowsr{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); //ChromeOptions object ChromeOptions opt ... Read More