Can Place Flowers in C++

Arnab Chakraborty
Updated on 11-Jun-2020 12:03:16

1K+ Views

Suppose we have a long flowerbed in which some of the plots are planted and some are empty. Now there is a constraint, flowers cannot be planted in adjacent plots, they would compete for water and both would die. So if we have a flowerbed, represented by an array containing 0 and 1, 0 indicates empty and 1 indicates fill, and a number n is also given, we have to check whether n new flowers can be planted in it without violating the no-adjacent-flowers rule or not.So, if the input is like flowerbed = [1, 0, 0, 0, 1], n ... Read More

Handle Proxy in Selenium with Java

Debomita Bhattacharjee
Updated on 11-Jun-2020 12:02:55

2K+ Views

We can handle proxy in Selenium in Java with the help of PROXY class.import java.io.IOException; import org.openqa.selenium.Proxy; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; public class ProxySelJav {    public static void main(String[] args) {       // TODO Auto-generated method stub       WebDriver driver;       String prox = "localhost:8080";       // set browser settings with Desired Capabilities       Proxy p = new Proxy(); p.setHttpProxy(prox).setFtpProxy(prox).setSslProxy(prox)       .setSocksProxy(prox);       DesiredCapabilities c = new DesiredCapabilities();       c.setCapability(CapabilityType.PROXY, p);       // utilize capabilities on launching ... Read More

Take Care of SSL Certificate Issues in Chrome Browser Using Selenium

Debomita Bhattacharjee
Updated on 11-Jun-2020 12:01:15

657 Views

We can face SSL certificate issue because of the reasons listed below −While the website was developed, its SSL certificate was not proper.The site may have a self-signed certificate.SSL not configured properly at the server level.Exampleimport org.openqa.selenium.Capabilities; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; public class SSLCert {    public static void main(String[] args) {       // TODO Auto-generated method stub       //Desired capabilities for general chrome profile       DesiredCapabilities c=DesiredCapabilities.chrome();       c.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);       c.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);       //ChromeOptions for local browser       ... Read More

Minimum Index Sum of Two Lists in C++

Arnab Chakraborty
Updated on 11-Jun-2020 12:00:29

202 Views

Suppose there are two fiends Amal and Bimal want to choose a restaurant for dinner, now they both have a list of favorite restaurants represented by strings. We have to help them to find out their common interest with the least list index sum. If there is a choice tie between different answers, then return all of them with no order requirement.So, if the input is like ["ABC", "PQR", "MNO", "XYZ"], and ["TUV", "GHI", "KLM", "ABC"], then the output will be ["ABC"]To solve this, we will follow these steps −Define one map mpleast := inffor initialize i := 0, when ... Read More

Use Properties File to Declare Global Variables in Selenium Framework

Debomita Bhattacharjee
Updated on 11-Jun-2020 11:59:39

2K+ Views

We can declare global variables in Selenium with the help of the Properties class which works with .properties file. In the .properties file, the data is stored in key value pairs. We can read and write values in the .properties file.Eaxmpleimport java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.Properties; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class Propert {    public static void main(String[] args) throws IOException {       // TODO Auto-generated method stub       Propert t = new Propert();       t.login();    }    public void login() throws IOException {       Properties ... Read More

Range Addition II in C++

Arnab Chakraborty
Updated on 11-Jun-2020 11:59:08

227 Views

Suppose we have one m * n matrix called M and this is initialized with all 0's and we also have several update operations. Now, operations are represented by a 2D array, and each operation is represented by an array with two positive integers x and y, it means M[i][j] should be added by one for all values i in range 0 to a - 1 and all values j in range 0 to b - 1. We have to find the count of the number of maximum integer in the matrix after performing all the operations.So, if the input ... Read More

Longest Harmonious Subsequence in C++

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

521 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

386 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

654 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

308 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

Advertisements