Longest Harmonious Subsequence in C++

Arnab Chakraborty
Updated on 11-Jun-2020 11:56:24

539 Views

Suppose we have an integer array; we have to find the length of its longest harmonious subsequence among all its possible subsequences. As we know a harmonious sequence array is an array where the difference between its maximum value and its minimum value is exactly 1.So, if the input is like [1, 3, 2, 2, 5, 2, 3, 7], then the output will be 5, as the longest harmonious subsequence is [4, 3, 3, 3, 4].To solve this, we will follow these steps −Define one map mfor n in nums −(increase m[n] by 1)for key-value pair (k, v) in m ... Read More

Capture Screenshots in Selenium

Debomita Bhattacharjee
Updated on 11-Jun-2020 11:55:19

403 Views

We can capture screenshots in Selenium with the help of TakesScreenshot interface. For capturing the screenshot and holding it in a specific location, getScreenshotAs() method is used.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import java.io.File; import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; public class ScreenshotFull{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url = "https://www.tutorialspoint.com/questions/index.php";       driver.get(url);       driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);       // capture screenshot with getScreenshotAs() and store in the //Screenshots folder   ... Read More

N-ary Tree Preorder Traversal in C++

Arnab Chakraborty
Updated on 11-Jun-2020 11:54:51

680 Views

Suppose we have one n-ary tree, we have to find the preorder traversal of its nodes.So, if the input is likethen the output will be [1,3,5,6,2,4]To solve this, we will follow these steps −Define an array ansDefine a method called preorder(), this will take rootif root is null, then −return empty listinsert value of root at the end of ansfor all child i in children array of rootpreorder(i)return ansExample Let us see the following implementation to get a better understanding − Live Demo#include using namespace std; void print_vector(vector v){    cout

Distribute Candies in C++

Arnab Chakraborty
Updated on 11-Jun-2020 11:53:30

328 Views

Suppose we have an array with even length, here different numbers in this array will represent different kinds of candies. Now each number means one candy of the corresponding kind. we have to distribute candies equally in number to brother and sister. We have to find the maximum number of kinds of candies the sister could receive.So, if the input is like [1, 1, 2, 3], then the output will be 2 as if we consider the sister has candies [2, 3] and the brother has candies [1, 1]. Now the sister has two different kinds of candies, the brother ... Read More

Verify Multiple Options Selection in Static Dropdown in Selenium

Debomita Bhattacharjee
Updated on 11-Jun-2020 11:53:30

2K+ Views

We can verify if we can select multiple options in a static dropdown in Selenium with the help of isMultiple() method. It returns a Boolean value of true or false.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import java.util.List; import org.openqa.selenium.support.ui.Select; public class OptionsMultiple{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url = "https://www.tutorialspoint.com/tutor_connect/index.php";       Select s = new Select(driver.findElement(By.xpath("//select[@name=’selType’]")));       // isMultiple() returns a boolean value       boolean result = s.isMultiple();       ... Read More

Select Value in Dropdown Without Select Class in Selenium

Debomita Bhattacharjee
Updated on 11-Jun-2020 11:52:02

5K+ Views

We can select a particular value in a dropdown using the method of Select class by using findElements() method.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import java.util.List; import org.openqa.selenium.support.ui.Select; public class OptionsClick{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url = "https://www.tutorialspoint.com/tutor_connect/index.php";       driver.get(url);       driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);       // getting the list of elements with the xpath       List opt = driver.findElements(By.xpath("//select[@name=’selType’]//option"));       int s = opt.size();       ... Read More

Reshape the Matrix in C++

Arnab Chakraborty
Updated on 11-Jun-2020 11:52:00

2K+ Views

In different platform there is very useful function called 'reshape', that function is used to reshape a matrix into a new one with different size but data will be same. So, if we have a matrix and two values r and c for the row number and column number of the wanted reshaped matrix, respectively.So, if the input is like [[5, 10], [15, 20]], row = 1 and col = 4, then the output will be [[5, 10, 15, 20]]To solve this, we will follow these steps−Define an array tempDefine one 2D array res of size (r x c)count := ... Read More

Select Value from Static Dropdown in Selenium

Debomita Bhattacharjee
Updated on 11-Jun-2020 11:49:55

10K+ Views

The various methods available under Select class in Selenium to select avalue from a static dropdown. They are as listed below −selectByVisibleText(String args)This method is most commonly used in dropdowns. It is very simple to select an option in a dropdown and multiple selection box with this method. It takes a String parameter as argument and returns no values.Syntax −Select s = new Select(driver.findElement(By.id(">"))); s.selectByVisibleText("Selenium");selectByIndex(String args)This method takes the index of the option to select in the dropdown. It takes an int parameter as argument and returns no values.Syntax −Select s = new Select(driver.findElement(By.id(">"))); s.selectByIndex(1);selectByValue(String args)This method takes the value ... Read More

Get All Options in Dropdown using Selenium

Debomita Bhattacharjee
Updated on 11-Jun-2020 11:46:37

24K+ Views

We can extract all the options in a dropdown in Selenium with the help of Select class which has the getOptions() method. This retrieves all the options on a Select tag and returns a list of web elements. This method does not accept any arguments.Exampleimport org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import java.util.List; import org.openqa.selenium.support.ui.Select; public class DropdownOptions{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String url = " https://www.tutorialspoint.com/tutor_connect/index.php";       driver.get(url);       driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);     ... Read More

Methods Available Under Select Class in Selenium

Debomita Bhattacharjee
Updated on 11-Jun-2020 11:44:02

1K+ Views

The various methods available under Select class in Selenium are listed below −selectByVisibleText(String args)This method is most commonly used in dropdowns. It is very simple to select an option in a dropdown and multiple selection box with this method. It takes a String parameter as argument and returns no values.Syntax −Select s = new Select(driver.findElement(By.id(">"))); s.selectByVisibleText("Selenium");selectByIndex(String args)This method takes the index of the option to select in the dropdown. It takes an int parameter as argument and returns no values.Syntax −Select s = new Select(driver.findElement(By.id(">"))); s.selectByIndex(1);selectByValue(String args)This method takes the value of the option to select in the dropdown. It ... Read More

Advertisements