Suppose we have two strings; we have to find the longest uncommon subsequence of these two strings. The longest uncommon subsequence is actually the longest subsequence of one string and this subsequence should not come in the other string. So, we have to find the length of the longest uncommon subsequence. If the longest uncommon subsequence doesn't exist, return -1.So, if the input is like "aabbac", "aabbcc", then the output will be 6To solve this, we will follow these steps −if a is same as b, then −return -1Otherwisereturn maximum of size of a and size of bExample Let us see ... Read More
Each of the locators has some significance. If the page contains uniqueattribute values, we should use them first. However if there are no unique elements, we should use css selector as it is more effective in terms of speed.Css also has a drawback that we cannot traverse from child to parent node which means we cannot travel backward. But xpath allows this feature. Xpath is the most common locator in Selenium and performs traversal through DOM elements and attributes to identify an object.An xpath is represented by two ways namely ‘/ ‘and ‘// ‘. A forward single slash means absolute ... Read More
Suppose we have to check whether a given number is perfect number or not. A number is said to be a Perfect Number when that is equal to the sum of all its positive divisors except itself. The number n will be in range 1^8.So, if the input is like 28, then the output will be True, as its sum of divisors − 1 + 2 + 4 + 7+ 14 = 28.To solve this, we will follow these steps −As the numbers are in range 10^8, there are only few perfect numbers, if the given input is in that ... Read More
Suppose we have a list of scores of N athletes, we have to find their relative ranks and the people with the top three highest scores, who will be different medals: "Gold", "Silver" and "Bronze".So, if the input is like [2, 5, 3, 1, 0], then the output will be [Bronze, Gold, Silver, 4, 5]To solve this, we will follow these steps −if size of nums is same as 1, then −return "Gold"if size of nums is same as 2, then −if nums[0] > nums[1], then −return "Gold", "Silver"Otherwisereturn "Silver", "Gold"Define an array vDDefine an array vecfor initialize i := ... Read More
Given a list of words, we have to find those words that can be typed using letters of the alphabet on only one row's of standard keyboard layout.So, if the input is like ["hello", "world", "mom", "dad", "try", "type", "tom"], then the output will be ["dad", "try", "type"]To solve this, we will follow these steps −Define an array outputoneRow := trueDefine one map charToRowMap, this will take all pairs such that {letter, line}, the letter is the letter present on the keyboard, and line is the line number on the keyboard.for each word in words array −if the word is ... Read More
To identify elements based on text visible on page, text() method is used in xpath.Syntax −driver.findElement(By.xpath("//tagname[text()=’value’]"))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; public class TextMatch { 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/index.htm"; driver.get(url); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); //xpath with text() method driver.findElement(By.xpath("//*[text()=’GATE Exams’]")).click(); driver.close(); } }Read More
We can identify elements by partially comparing to its attributes in Selenium with the help of regular expression. In xpath, there is contains () method. It supports partial matching with the value of the attributes. This method comes as useful while dealing with elements having dynamic values in their attributes.Syntax driver.findElement(By.xpath("//tagname[contains(@attributes, ’value’)]"))In CSS, we can identify elements by partially comparing to its attributes by using regular expressions. There can be three scenarios −Using ^ to target attributes starting with a particular text.Syntax −driver.findElement(By.cssSelector("tagname[attribute^=’value’]"))Using $ to target attributes ending with a particular text.Syntax −driver.findElement(By.cssSelector("tagname[attribute$=’value’]"))Using * to target attributes containing a particular text.Syntax −driver.findElement(By.cssSelector("tagname[attribute*=’value’]"))Exampleimport org.openqa.selenium.By; ... Read More
Suppose we have a specific rectangular web page area, our job is to design a rectangular web page, whose length L and width W that satisfies the following requirements −The area of the web page must equal to the given target area.The width W should not be larger than the length L, and L >= W.The difference between L and W should be as small as possible.So, if the input is like 4, then the output will be [2, 2], as the target area is 4, and all the possible ways to construct it are [1, 4], [2, 2], [4, ... Read More
Suppose we have to design a standard heater with a fixed warm radius to warm all the houses. Now, we have given positions of houses and heaters on a horizontal line, we have to find the minimum radius of heaters so that all houses could be covered by those heaters. So, we will provide houses and heaters separately, and our expected output will be the minimum radius standard of heaters.So, if the input is like [1, 2, 3, 4], [1, 4], then the output will be 1 as the two heaters was placed in position 1 and 4. We have ... Read More
Suppose we are trying to distribute some cookies to children. But, we should give each child at most one cookie. Now each child i has a greed factor gi, which is the minimum size of a cookie that the child will be content with; and each cookie j has a size sj. When sj >= gi, we can assign the cookie j to the child i, and the child i will be content. Our goal is to maximize the number of content children and output the maximum number.So, if the input is like [1, 2], [1, 2, 3], then the ... Read More
 
 Data Structure
 Data Structure Networking
 Networking RDBMS
 RDBMS Operating System
 Operating System Java
 Java MS Excel
 MS Excel iOS
 iOS HTML
 HTML CSS
 CSS Android
 Android Python
 Python C Programming
 C Programming C++
 C++ C#
 C# MongoDB
 MongoDB MySQL
 MySQL Javascript
 Javascript PHP
 PHP 
		