Suppose we have an array nums that contains the lengths 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 the polygon inequality theorem where the length of the longest side must be smaller than the sum of all other sides. Algorithm To solve this, we ... 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, where a = 0, b = 1... j = 9. So if the number is 42, the substring "ec" will be repeated till we reach 6 (4+2) characters "ececec", then check if 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 ... Read More
Given two strings containing only characters 'A', 'B', and '#', we need to check if string s can be transformed into string t following these movement rules: 'A' can only move to the left 'B' can only move to the right 'A' and 'B' cannot cross each other '#' represents empty spaces Approach The solution involves validating that each character in s can move to its corresponding position in t without violating the movement constraints ? Algorithm Steps ... Read More
Given an array of numbers and a target sum, we need to check if it's possible to achieve the target sum by adding elements from the array. Elements can be used multiple times. For example, with nums = [2, 3, 5] and sum = 28, the answer is True because we can get 28 using: 5 + 5 + 5 + 5 + 3 + 3 + 2 = 28. Approach We'll use dynamic programming with a boolean table to track all possible sums that can be formed ? Create a boolean table where table[i] ... Read More
Given a string, we need to check whether it can be split into four non-empty and distinct substrings. This problem involves finding all possible ways to partition the string into exactly four parts and verifying that all parts are unique. For example, if the input string is "helloworld", one valid split would be ["hel", "lo", "wor", "ld"] since all four substrings are distinct. Algorithm Approach The solution uses a brute force approach with three nested loops to generate all possible splits ? If the string length is ≥ 10, return True (optimization: with 10+ characters, ... Read More
A perfect square is a number that can be expressed as the product of an integer with itself. In other words, a number is a perfect square when its square root is an integer. For example, 36 is a perfect square because √36 = 6, and 6 is an integer. In this tutorial, we'll explore different methods to check if a given number is a perfect square in Python. Algorithm To check if a number is a perfect square, we follow these steps ? Calculate the square root of the given number Take the integer ... Read More
An Emirp number is a prime number that becomes a different prime when its digits are reversed. The term "Emirp" is "prime" spelled backwards. For a number to be Emirp, it must be prime, and its reverse must also be prime (and different from the original). For example, 97 is an Emirp number because 97 is prime, and its reverse 79 is also prime. Algorithm To check if a number is Emirp, we follow these steps ? Check if the number is prime If not prime, return False Calculate the reverse of the number Check ... Read More
Given a number n and another value d, we need to check whether n is a power of d, where d itself is a power of 2. For example, if n = 32768 and d = 32, the result is True because 32768 = 32³. Algorithm To solve this problem, we follow these steps: First, check if n is a power of 2 using bitwise operations Count how many times we can divide n by 2 to get the power of n as base 2 Count how many times we can divide d by 2 to ... Read More
Bokeh is a powerful Python library for creating interactive data visualizations that render in web browsers. It converts data into JSON format and uses BokehJS (written in TypeScript) to create interactive plots using HTML and JavaScript. Installation Install Bokeh using pip or conda ? pip install bokeh Or using Anaconda ? conda install bokeh Creating a Grid Plot with Image A grid plot displays data as a 2D image with customizable grid lines. Here's how to create one using mathematical functions ? import numpy as np from ... Read More
Bokeh is a Python package that helps in data visualization. It is an open source project. Bokeh renders its plot using HTML and JavaScript. This indicates that it is useful while working with web-based dashboards. Matplotlib and Seaborn produce static plots, whereas Bokeh produces interactive plots. This means when the user interacts with these plots, they change accordingly. Plots can be embedded as output of Flask or Django enabled web applications. Jupyter notebook can also be used to render these plots. Installation Installation of Bokeh on Windows command prompt: pip3 install bokeh ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Economics & Finance