Programming Articles

Page 552 of 2547

Maximum factors formed by two numbers in Python

Sunidhi Bansal
Sunidhi Bansal
Updated on 25-Mar-2026 2K+ Views

We are given an array of integers and need to find the maximum number of factors formed by multiplying any two distinct numbers from the array. This involves calculating all possible products of pairs and then counting factors for each product. Problem Understanding Example 1 For array [3, 2, 10] ? Input: [3, 2, 10] Products: 3×2=6, 3×10=30, 2×10=20 Factors: 6→{1, 2, 3, 6} (4 factors), 30→{1, 2, 3, 5, 6, 10, 15, 30} (8 factors), 20→{1, 2, 4, 5, 10, 20} (6 factors) Output: Maximum factors = 8 Example 2 For ...

Read More

Find bitonic point in given bitonic sequence in Python

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

A bitonic sequence is a sequence of numbers that first increases strictly, reaches a peak (the bitonic point), then decreases strictly. We need to find this peak element efficiently using binary search. The bitonic point is the maximum element where the left neighbor is smaller and the right neighbor is also smaller. Algorithm We use binary search to find the bitonic point in O(log n) time ? Compare the middle element with its neighbors If array[mid-1] < array[mid] > array[mid+1], we found the bitonic point If array[mid] < array[mid+1], the peak is in the right ...

Read More

Find array with k number of merge sort calls in Python

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

Sometimes we need to construct an array that requires exactly k recursive calls when sorted using merge sort. This problem involves understanding how merge sort's recursive structure works and manipulating an array to achieve the desired call count. Given two numbers a and b, we need to find an array containing values in range [1, a] that requires exactly b number of recursive merge sort calls. Understanding the Problem Merge sort makes recursive calls by dividing the array into halves. The total number of calls follows a pattern based on the array structure and element positions. ...

Read More

Find an element which divides the array in two subarrays with equal product in Python

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

Given an array of integers, we need to find an element that divides the array into two subarrays with equal product. If no such element exists, return -1. For example, in the array [2, 5, 3, 2, 5], the element 3 at index 2 divides it into subarrays [2, 5] and [2, 5], both having product 10. Algorithm We use prefix and suffix product arrays to efficiently calculate products of left and right subarrays ? Create a prefix product array storing cumulative products from left Create a suffix product array storing cumulative products from right ...

Read More

Find an element in an array such that elements form a strictly decreasing and increasing sequence in Python

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

In Python, we can find an element in an array where elements form a strictly decreasing sequence followed by a strictly increasing sequence. The element we seek is the transition point between these two sequences. Problem Requirements The solution must satisfy these conditions: Both decreasing and increasing sequences must have minimum length 2 The last value of the decreasing sequence is the first value of the increasing sequence No duplicate elements are allowed (strictly decreasing/increasing) For example, in array [5, 4, 3, 4], the sequence [5, 4, 3] is strictly decreasing and [3, 4] ...

Read More

Find all strings formed from characters mapped to digits of a number in Python

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

When working with digit-to-character mappings, we often need to generate all possible string combinations from a given number. This is similar to how old mobile phone keypads worked, where each digit mapped to multiple letters. Problem Understanding Given a mapping where each digit (1-9) corresponds to a list of characters, we need to find all possible strings that can be formed from a number. The key constraint is that we must use the same character for every occurrence of a digit in the number. 1 → ['A', 'B', 'C'] 2 → ['D', 'E', 'F'] ...

Read More

Find all rectangles filled with 0 in Python

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

Finding all rectangles filled with 0s in a binary 2D matrix is a common problem in computer vision and image processing. We need to identify the starting and ending coordinates of each rectangular region containing only zeros. The problem requires us to find rectangles that are separated (don't touch each other) but can touch array boundaries. Each rectangle is represented by four coordinates: [start_row, start_col, end_row, end_col]. Input Example Consider this binary matrix where 1 represents filled cells and 0 represents empty cells ? 1011101 1101111 1011001 1011001 1011011 1010000 1110001 1011101 Algorithm ...

Read More

Find all palindromic sub-strings of a given string - Set 2 in Python

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

A palindrome is a string that reads the same forwards and backwards. Finding all palindromic sub-strings involves checking every possible substring. This implementation uses the expand around centers approach with fractional positions to handle both odd and even-length palindromes efficiently. How the Algorithm Works The algorithm uses fractional positions (0.0, 0.5, 1.0, 1.5...) to represent centers: Integer positions (0, 1, 2...) represent centers of odd-length palindromes Half positions (0.5, 1.5, 2.5...) represent centers of even-length palindromes For each center, expand outward while characters match Implementation Here's the complete solution that finds all palindromic ...

Read More

Find all good indices in the given Array in Pytho

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

Given an array of numbers, we need to find all indices where removing that element results in a good array. A good array is one where at least one element equals the sum of all other elements in the array. The problem uses 1-based indexing, meaning the first element is at index 1, not 0. Understanding the Problem For the array [10, 4, 6, 2]: Removing index 1 (element 10): [4, 6, 2] → 6 = 4 + 2 ✓ Removing index 2 (element 4): [10, 6, 2] → 10 ≠ 6 + 2 ✗ ...

Read More

Find all distinct palindromic sub-strings of a given String in Python

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

Finding all distinct palindromic substrings is a common string processing problem. A palindrome is a string that reads the same forwards and backwards. This solution uses Manacher's algorithm to efficiently find all palindromic substrings. So, if the input is like "bddaaa", then the output will be [a, aa, aaa, b, d, dd] Understanding the Algorithm The algorithm follows these key steps: Create a matrix to store palindrome lengths at each position Process the string with padding characters to handle edge cases Use Manacher's algorithm to find all palindromes efficiently Extract distinct palindromic substrings using a ...

Read More
Showing 5511–5520 of 25,466 articles
« Prev 1 550 551 552 553 554 2547 Next »
Advertisements