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
Articles on Trending Technologies
Technical articles with clear explanations and examples
Program to check we can get a digit pair and any number of digit triplets or not in Python
Suppose we have a numeric string s. We have to check whether there is some arrangement where we can have one pair of the same character and the rest of the string form any number of triplets of the same characters. So, if the input is like s = "21133123", then the output will be True, because there are two 2s to form "22" as the pair and "111", "333" as two triplets. Algorithm To solve this, we will follow these steps ? d := a list containing frequencies of each elements ...
Read MoreProgram to check string is palindrome with lowercase characters or not in Python
Suppose we have an alphanumeric string s that can hold both uppercase and lowercase letters. We need to check whether s is a palindrome considering only the lowercase alphabet characters. So, if the input is like s = "rLacHEec0a2r8", then the output will be True because the string contains "racecar" in lowercase, which is a palindrome. Algorithm To solve this, we will follow these steps − Extract all lowercase characters from the string Check if the extracted string equals its reverse Return True if palindrome, False otherwise Example Let us see the ...
Read MoreProgram to find mutual followers from a relations list in Python
Suppose we have a list called relations, where each element relations[i] contains two numbers [ai, bi] indicating that person ai is following bi on a social media platform. We need to find mutual followers − people who follow someone and are followed back by them. The result should be returned in sorted order. So, if the input is like relations = [[0, 2], [2, 3], [2, 0], [1, 0]], then the output will be [0, 2] because person 0 follows person 2, and person 2 follows person 0 back. Algorithm To solve this, we will follow these ...
Read MoreProgram to find minimum number of monotonous string groups in Python
Suppose we have a lowercase string s. We need to find the minimum number of contiguous substrings that s can be divided into, where each substring is either non-increasing (monotonically decreasing) or non-decreasing (monotonically increasing). For example, "pqqqr" is a non-decreasing string, and "qqqp" is a non-increasing string. Problem Example If the input is s = "pqrsrqp", then the output will be 2, because we can break s into "pqrs" (non-decreasing) and "rqp" (non-increasing). Algorithm Steps To solve this problem, we follow these steps ? If string is empty, ...
Read MoreProgram to find minimum value to insert at beginning for all positive prefix sums in Python
Suppose we have a list of numbers called nums. We have to find the minimum positive value that we can insert at the beginning of nums so that the prefix sums of the resulting list are all positive (greater than 0). So, if the input is like nums = [3, -6, 4, 3], then the output will be 4, because if we insert 4 to the list then we have [4, 3, -6, 4, 3]. Now the prefix sums are [4, 7, 1, 5, 8], all are positive. Algorithm To solve this, we will follow these steps ...
Read MoreProgram to find minimum distance of two given words in a text in Python
Finding the minimum distance between two words in a text is a common string processing problem. The distance is measured as the number of words between any occurrence of the two target words. Given a text string and two words w1 and w2, we need to find the smallest number of words between any occurrences of these words. If either word is not present, we return -1. Algorithm The approach involves tracking the most recent positions of both words as we iterate through the text ? Initialize index1 and index2 as None Set distance to ...
Read MoreProgram to find minimum amplitude after deleting K elements in Python
Given a list of numbers and a value k, we need to find the minimum amplitude (difference between maximum and minimum) after removing k elements from the list. So, if the input is like nums = [4, 10, 3, 2, 8, 9] and k = 3, then the output will be 2. If we remove 10, 8, and 9, the remaining elements are [4, 3, 2], where maximum is 4 and minimum is 2, giving us an amplitude of 2. Algorithm To solve this problem, we will follow these steps ? ...
Read MoreProgram to find maximum product of two distinct elements from an array in Python
Given an array of numbers, we need to find the maximum product of two distinct elements. The key insight is that the maximum product can come from either the two largest numbers or the two smallest numbers (if they are both negative). For example, if the input is nums = [8, -3, 1, -5], the output will be 15 because (-3) * (-5) = 15, which is the maximum product possible. Approach To solve this problem, we follow these steps ? Sort the array to get elements in ascending order ...
Read MoreProgram to find largest product of three unique items in Python
Suppose we have a list of numbers called nums, we have to find the largest product of three unique elements. So, if the input is like nums = [6, 1, 2, 4, -3, -4], then the output will be 72, as we can multiply (-3) * (-4) * 6 = 72. Algorithm To solve this, we will follow these steps − Sort the list nums n := size of nums maxScore := -infinity maxScore := maximum of maxScore and ...
Read MoreProgram to find maximum sum of multiplied numbers in Python
Given two lists nums and multipliers, we need to find the maximum sum by pairing and multiplying elements from both lists. We can remove any number from either list and multiply them together, repeating until one list is empty. The key insight is to pair negative multipliers with the smallest numbers and positive multipliers with the largest numbers to maximize the sum. Algorithm To solve this problem, we follow these steps: Sort both lists in ascending order Ensure nums is the longer list (swap if needed) For each multiplier: If multiplier ≤ 0: pair ...
Read More