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
Programming Articles
Page 545 of 2547
Find largest subtree having identical left and right subtrees in Python
Finding the largest subtree with identical left and right subtrees involves comparing the structure and values of subtrees. We'll use a recursive approach with tree encoding to efficiently identify matching subtrees. 55 15 70 10 25 ...
Read MoreFind k-th character of decrypted string - Set – 2 in Python
Sometimes we need to decode an encoded string where repetitions of substrings are represented as substring followed by count of substrings. For example, if the string is "pq2rs2" and we want the 5th character, the output will be 'r', because the decrypted string is "pqpqrsrs" and the 5th character is 'r'. We have to keep in mind that the frequency of encrypted substring can be of more than one digit. So, if the input is like string = "pq4r2ts3" and k = 11, then the output will be 't', as the decoded string is "pqpqpqpqrrtststs". Algorithm To ...
Read MoreFind Indexs of 0 to be replaced with 1 to get longest continuous sequence of 1s in a binary array - Set-2 in Python
In binary arrays, we often need to find the optimal position to flip a 0 to 1 to create the longest possible sequence of consecutive 1s. This problem requires tracking sequences on both sides of each 0 to determine which replacement yields maximum benefit. Given a binary array like [1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1], we need to find which 0 should be replaced to get the longest continuous sequence of 1s. The answer is index 10, creating [1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1]. ...
Read MoreFind index i such that prefix of S1 and suffix of S2 till i form a palindrome when concatenated in Python
Given two strings S1 and S2 of the same length, we need to find an index i such that the prefix S1[0...i] and suffix S2[i+1...n-1] form a palindrome when concatenated. If no such index exists, return -1. For example, with S1 = "pqrsu" and S2 = "wxyqp", we find that S1[0..1] = "pq" and S2[2..4] = "yqp" combine to form "pqyqp", which is a palindrome at index 1. Algorithm To solve this problem, we follow these steps − Initialize n as the length of both strings For each index i from 0 to n-1: ...
Read MoreFind if there is a path of more than k length from a source in Python
Finding a path longer than a given length in a graph is a classic graph traversal problem. We need to determine if there exists a simple path (without cycles) from a source vertex to any other vertex with total edge weights exceeding a threshold k. 0 1 2 ...
Read MoreFind if neat arrangement of cups and shelves can be made in Python
Suppose we have three different types of cups in array p and saucers in array q, and m number of shelves. We need to check whether a neat arrangement of cups and saucers can be made following specific constraints. The arrangement is considered neat if it follows these conditions: No shelf can hold both cups and saucers A shelf may contain at most 5 cups A shelf may contain at most 10 saucers Problem Understanding Given arrays p = [4, 3, 7], q = [5, 9, 10], and m = 11, we need to ...
Read MoreFind if it is possible to get a ratio from given ranges of costs and quantities in Python
Suppose we have a range of cost from lowCost to upCost and another range of quantity from lowQuant to upQuant. We need to check whether we can find the given ratio r where r = cost/quantity, with lowCost ≤ cost ≤ upCost and lowQuant ≤ quantity ≤ upQuant. So, if the input is like lowCost = 2, upCost = 10, lowQuant = 3, upQuant = 9 and r = 3, then the output will be True as the cost = r * quantity = 3 * 3 = 9 where cost is in range [2, 10] and quantity is ...
Read MoreFind if given vertical level of binary tree is sorted or not in Python
In binary tree problems, we often need to analyze nodes at specific vertical levels. A vertical level represents all nodes that are at the same horizontal distance from the root. This problem asks us to check if nodes at a given vertical level are sorted in ascending order. Understanding Vertical Levels In a binary tree, vertical levels are determined by horizontal distance from the root ? Root node is at vertical level 0 Left child is at (parent's level - 1) Right child is at (parent's level + 1) ...
Read MoreFind if an undirected graph contains an independent set of a given size in Python
An independent set in an undirected graph is a set of vertices where no two vertices are adjacent (directly connected by an edge). This article demonstrates how to find if a graph contains an independent set of a given size using Python. We need to check whether a graph contains an independent set of size k. If such a set exists, return "Yes", otherwise "No". Problem Understanding Given an undirected graph represented as an adjacency matrix, we want to find k vertices such that none of them are connected to each other. For example, if k = ...
Read MoreFind Four points such that they form a square whose sides are parallel to x and y axes in Python
Finding four points that form a square with sides parallel to the coordinate axes is a geometric problem. We need to identify diagonal points first, then verify if the other two corner points exist in our point set. Problem Approach To form a square with sides parallel to x and y axes, we need four points that satisfy these conditions ? Two points should form a diagonal of the square The diagonal points must have equal x-distance and y-distance The other two corner points must exist in our point set If multiple squares exist, select the ...
Read More