Python Articles

Page 116 of 855

Program to find number of rectangles that can form the largest square in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 369 Views

Suppose we have an array called rect where rect[i] has two elements [len_i, wid_i], where len_i and wid_i are representing the length and width of ith rectangle respectively. Now we can cut the ith rectangle to form a square whose side length is of k if both k

Read More

Program to recover decode XORed array in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 440 Views

Suppose we have a hidden array arr with n non-negative integers. This array is encoded into another array enc of length n-1, where enc[i] = arr[i] XOR arr[i+1]. Given the encoded array and the first element of the original array, we need to recover the original array. So, if the input is like enc = [8, 3, 2, 7], first = 4, then the output will be [4, 12, 15, 13, 10]. Algorithm To solve this, we will follow these steps − arr := an array with only one element first for i in range ...

Read More

Program to find total amount of money we have in bank in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 600 Views

Suppose you put 1Rs in a bank on the first day (Monday). Each subsequent day of the week, you put in 1Rs more than the previous day. On every new Monday, you start with 1Rs more than the previous Monday. This creates a pattern where the amount increases both daily and weekly. For example, if n = 17 days: Week 1: 1Rs (Mon) + 2Rs (Tue) + 3Rs (Wed) + 4Rs (Thu) + 5Rs (Fri) + 6Rs (Sat) + 7Rs (Sun) = 28Rs Week 2: 2Rs (Mon) + 3Rs (Tue) + 4Rs (Wed) + 5Rs (Thu) + 6Rs ...

Read More

Program to find maximum units that can be put on a truck in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 758 Views

Suppose we have a set of boxes represented as a 2D array called boxTypes, where boxTypes[i] contains two elements [number of boxes of type i, number of units per box of type i]. Now we also have another value k, which is the maximum number of boxes that can be put on that truck. We can select any boxes to put on the truck as long as the number of boxes does not cross k. We have to find the maximum total number of units that can be put on the truck. Problem Understanding So, if the input ...

Read More

Program to check whether String Halves Are Alike in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 509 Views

Suppose we have a string s whose length is even. We have to split this string into two different halves of same lengths. So consider 'a' is the first half and 'b' is the second half. We say two strings are alike when they have the same number of vowels (uppercase or lowercase). We have to check whether 'a' and 'b' are alike or not. So, if the input is like s = "talent", then the output will be True because two halves are "tal" and "ent", they are alike because they have only one vowel each. Algorithm ...

Read More

Program to find reformatted phone number in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 447 Views

Phone number formatting is a common task in data processing. Given a phone number string containing digits, spaces, and dashes, we need to reformat it according to specific grouping rules. Problem Requirements The reformatting follows these rules: Remove all spaces and dashes first Group digits from left to right into blocks of 3 until 4 or fewer digits remain Handle the final digits based on count: 2 digits: Single block of length 2 3 digits: Single block of length 3 4 digits: Two blocks of length 2 each Join all blocks with dashes ...

Read More

Program to count number of matches played in tournament in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 2K+ Views

Suppose we have a number n representing the number of teams in a tournament. The tournament follows specific rules to determine matches and winners ? If the number of teams is even, each team gets paired with another team. A total of (n/2) matches are played, and (n/2) winner teams advance to the next round. If the number of teams is odd, one team randomly advances to the next round without playing. The remaining teams get paired, so (n-1)/2 matches are played, and (n-1)/2 + 1 teams advance as winners. ...

Read More

Program to count the number of consistent strings in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 749 Views

Suppose we have a string s consisting of distinct characters and also have an array of strings called words. A string is consistent when all characters in the string appear in the string s. We have to find the number of consistent strings present in the array words. So, if the input is like s = "px", words = ["ad", "xp", "pppx", "xpp", "apxpa"], then the output will be 3 because there are three strings with only 'p' and 'x': ["xp", "pppx", "xpp"]. Algorithm To solve this, we will follow these steps − ...

Read More

Program to find goal parser interpretation command in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 532 Views

Suppose we have a Goal Parser that can interpret a given string command. A command consists of: An alphabet "G" Opening and closing parenthesis "()" and/or "(al)" in some order Our Goal Parser will interpret "G" as the string "G", "()" as "o", and "(al)" as the string "al". Finally interpreted strings are then concatenated in the original order. Problem Statement Given a string command, we need to find the Goal Parser's interpretation of the command. For example, if the input is command = "G()()()(al)(al)", then the output will be "Goooalal". Approach ...

Read More

Python Program to find out the number of sets greater than a given value

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 389 Views

Suppose we have an array containing several integer numbers. We need to find all contiguous subarrays, replace each subarray with its maximum element, and count how many of these maximum values are greater than a given number k. So, if the input is like input_array = [5, 6, 7, 8], k = 7, then the output will be 4. Understanding the Problem The contiguous subarrays from the given input array are: {5}, {6}, {7}, {8}, {5, 6}, {6, 7}, {7, 8}, {5, 6, 7}, {6, 7, 8}, {5, 6, 7, 8} If we replace each subarray ...

Read More
Showing 1151–1160 of 8,549 articles
« Prev 1 114 115 116 117 118 855 Next »
Advertisements