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 541 of 2109
Find lost element from a duplicated array in Python
Finding a lost element from a duplicated array is a common problem where two arrays are identical except one element is missing from one of them. We need to identify which element is missing efficiently. So, if the input is like A = [2, 5, 6, 8, 10], B = [5, 6, 8, 10], then the output will be 2 as 2 is missing from second array. Using Binary Search Approach The most efficient approach uses binary search to find the missing element in O(log n) time complexity ? def solve(A, B, N): ...
Read MoreFind longest palindrome formed by removing or shuffling chars from string in Python
Suppose we have a string; we have to find the longest palindrome that can be generated by deleting or shuffling the characters from the string. If there are more than one palindrome, then return only one. So, if the input is like pqqprrs, then the output will be pqrsrqp. Approach To solve this problem, we will follow these steps ? Count the frequency of each character in the string For each character, use pairs to form the left and right sides of the palindrome ...
Read MoreFind longest bitonic sequence such that increasing and decreasing parts are from two different arrays in Python
A bitonic sequence is a sequence that first increases and then decreases. In this problem, we need to find the longest bitonic sequence where the increasing part comes from the first array and the decreasing part comes from the second array, both as subsequences. Given two arrays A and B, we find the longest increasing subsequence from A, then the longest increasing subsequence from the reverse of B (which gives us a decreasing sequence), and combine them. Algorithm Overview The solution uses dynamic programming with binary search optimization: Find the longest increasing subsequence (LIS) from ...
Read MoreFind 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 More