Suppose we have an array nums that contain the size of n sides. We have to check whether we can form a polygon with all of the given sides or not.So, if the input is like nums = [3, 4, 5], then the output will be True because there are three sides and sum of any two sides is larger than the 3rd one. To solve this, we will use this property where length of one side is smaller than the sum of all other sides.To solve this, we will follow these steps −sort the list numsif last element of ... Read More
Suppose we have an angle a. We have to check whether we can make a regular polygon where all angles are same as a or not.So, if the input is like a = 120, then the output will be True the pentagon has all angles same as 120°. As we know$$Interior Angle(a)=\frac{180\times(n-2)}{n}\begin{bmatrix} n=number of sides of polygon\end{bmatrix}$$ $$¿n=\frac{360}{180-a}$$So if n is integer then this is forming a regular polygon.To solve this, we will follow these steps −sides := 360 /(180 - a)if sides has no fractional part, thenreturn Truereturn FalseExampleLet us see the following implementation to get better understanding − Live ... Read More
Suppose we have a number n. We have to check whether we can create an alphabetical lowercase string from that number and check whether the string is palindrome or not. Here we will take only characters from a to j, [a = 0, b = 1... j = 9]. So if the number is 42 the substring "ec" will be printed till 6 (4+2) characters "ececec" then check this is palindrome or not.So, if the input is like n = 43, then the output will be True the string is "ededede" and this is palindrome.To solve this, we will follow ... Read More
Suppose we have two strings s and t with only three characters 'A', 'B' and '#'. We have to check whether it is possible to convert s into t by performing these operations on s.'A' can move only to the left hand side'B' can move only to the right hand sideNeither 'A' nor 'B' can cross each otherSo, if the input is like s = "##AB##B" t = "A###B#B", then the output will be True as in s A can move easily to the left most position, and middle B can move one step to the rightTo solve this, we ... Read More
Suppose we have an array called nums and another value sum. We have to check whether it is possible to get sum by adding elements present in nums, we may pick a single element multiple times.So, if the input is like nums = [2, 3, 5] sum = 28, then the output will be True as we can get 26 by using 5 + 5 + 5 + 5 + 3 + 3 + 2To solve this, we will follow these steps −MAX := 1000table := an array of size MAX ad fill with 0Define a function util() . This ... Read More
Suppose we have a string s, we have to check whether we can split it into four sub-strings such that each of them are non-empty and unique.So, if the input is like s = "helloworld", then the output will be True as one of the possible set of sub-strings are ["hel", "lo", "wor", "ld"]To solve this, we will follow these steps −if size of s >= 10, thenreturn Truefor i in range 1 to size of s - 1, dofor j in range i + 1 to size of s - 1, dofor k in range j + 1 to ... Read More
BeautifulSoup is a third party Python library that is used to parse data from web pages. It helps in web scraping, which is a process of extracting, using, and manipulating the data from different resources.Web scraping can also be used to extract data for research purposes, understand/compare market trends, perform SEO monitoring, and so on.The below line can be run to install BeautifulSoup on Windows −pip install beautifulsoup4Following is an example −Examplefrom bs4 import BeautifulSoup import requests url = "https://en.wikipedia.org/wiki/Algorithm" req = requests.get(url) soup = BeautifulSoup(req.text, "html.parser") print("The href links are :") for link in soup.find_all('a'): print(link.get('href'))OutputThe href links ... Read More
BeautifulSoup is a third party Python library that is used to parse data from web pages. It helps in web scraping, which is a process of extracting, using, and manipulating the data from different resources.Web scraping can also be used to extract data for research purposes, understand/compare market trends, perform SEO monitoring, and so on.The below line can be run to install BeautifulSoup on Windows −pip install beautifulsoup4Let us see an example −Exampleimport requests from bs4 import BeautifulSoup from urllib.request import urlopen import urllib url = 'https://en.wikipedia.org/wiki/Algorithm' html = urlopen(url).read() print("Reading the webpage...") soup = BeautifulSoup(html, features="html.parser") print("Parsing the webpage...") ... Read More
Suppose we have a number n. We have to check whether the number n is perfect square or not. A number is said to be a perfect square number when its square root is an integer.So, if the input is like n = 36, then the output will be True as 36 = 6*6.To solve this, we will follow these steps −sq_root := integer part of (square root of n)return true when sq_root^2 is same as n otherwise falseExampleLet us see the following implementation to get better understanding − Live Demofrom math import sqrt def solve(n): sq_root = int(sqrt(n)) ... Read More
Suppose we have a number n. We have to check whether n is an Emirp number or not. We all know Emirp number is (letters of prime in backward direction) is a prime number that results in a different prime when its digits are reversed.So, if the input is like n = 97, then the output will be True as the reverse of 97 is 79 which is another prime.To solve this, we will follow these steps −if num is not prime, thenreturn Falsereverse_num := reverse of numreturn true when reverse_num is prime otherwise falseExampleLet us see the following implementation ... Read More