Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 454 of 2109
Check if it is possible to convert one string into another with given constraints in Python
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 MoreCheck if is possible to get given sum from a given set of elements in Python
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 MoreCheck if given string can be split into four distinct strings in Python
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 MoreCheck if given number is perfect square in Python
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 MoreCheck if given number is Emirp Number or not in Python
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 MoreCheck if given number is a power of d where d is a power of 2 in Python
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 MoreHow can grid plot in Bokeh library be created with Python?
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 MoreHow can Bokeh library be used to visualize twin axes in Python?
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 MoreCheck if given four integers (or sides) make rectangle in Python
A rectangle is a quadrilateral with four right angles and two pairs of opposite sides that are equal in length. Given four integers representing sides, we need to check if they can form a rectangle. So, if the input is like sides = [10, 30, 30, 10], then the output will be True as there are two pairs of equal sides (10, 10) and (30, 30). Algorithm To solve this, we will follow these steps − If all four sides are equal, then it's a square (which is also a rectangle), ...
Read MoreCheck if given array is almost sorted (elements are at-most one position away) in Python
Suppose we have an array of numbers where all elements are unique. We need to check whether the array is almost sorted or not. An array is almost sorted when any of its elements can occur at a maximum of 1 distance away from its original position in the sorted array. For example, if we have nums = [10, 30, 20, 40], the output will be True because 10 is at its correct position and all other elements are at most one place away from their actual sorted position. Algorithm To solve this problem, we follow these ...
Read More