Programming Articles

Page 376 of 2547

Program to check whether String Halves Are Alike in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 513 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 452 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 755 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 535 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 395 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

Python Program to find out the determinant of a given special matrix

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

Determinants of special matrices formed from tree structures have important applications in graph theory and computational mathematics. In this problem, we construct an n×n matrix A where each element A(x, y) equals the weight of the least common ancestor (LCA) of vertices x and y in a tree. Problem Understanding Given a tree with n vertices labeled 1 to n, where vertex 1 is the root and each vertex has weight wi, we need to find the determinant of matrix A where A(x, y) = weight_of_LCA(x, y). Example Tree Structure For input edges [[1, 2], [1, ...

Read More

Python Program to find out the number of rooms in which a prize can be hidden

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

Suppose in a game show there are 2n rooms arranged in a circle. One room contains a prize that participants must find. The rooms are numbered 1, 2, 3, ..., n, -n, -(n-1), ..., -1 in clockwise order. Each room has a door with a marking x that indicates the distance to the next room. If x is positive, the door opens to the xth room clockwise; if negative, it opens to the xth room counter-clockwise. We need to find how many rooms can hide the prize such that participants cannot find it by following the door sequence. ...

Read More

Python Program to find out how many cubes are cut

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

Suppose we have several cubes of dimensions a, b, and c, and using them we create a new box of dimension a×b×c. The values a, b, and c are pairwise co-prime, meaning gcd(a, b) = gcd(b, c) = gcd(a, c) = 1. We need to cut the box into two pieces with a single slice and determine how many individual cubes are cut into two pieces. The cut is made through a plane that passes through specific vertices, creating a diagonal slice through the 3D box structure. Problem Statement Given an array containing multiple sets ...

Read More

Python Program to find out how many times the balls will collide in a circular tube

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

Suppose there are n balls in a circular tube that is 100 meters long. Initially, each ball is positioned at a specific distance from a starting point. The balls travel in different directions at a speed of 0.1 meters per second. When two balls meet, they collide and change their direction of travel. We need to find the total number of collisions that occur over 10^9 + 6 seconds. Problem Analysis The key insight is that balls moving in opposite directions will collide multiple times as they circle the tube. The collision count depends on: Number ...

Read More
Showing 3751–3760 of 25,466 articles
« Prev 1 374 375 376 377 378 2547 Next »
Advertisements