Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 119 of 377

Program to find contiguous intervals of a unique array in Python

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

Suppose we have a list of unique numbers called nums. We have to find a sorted 2D matrix of numbers where each list represents an inclusive interval summarizing numbers that are contiguous in nums. So, if the input is like nums = [10, 11, 12, 15, 16, 17, 28, 30], then the output will be [[10, 12], [15, 17], [28, 28], [30, 30]], as in the list [10 to 12], [15 to 17] are contiguous, and 28 and 30 are there, they are represented as [28 to 28] and [30 to 30]. Algorithm To solve this, we ...

Read More

Program to check string contains consecutively descending string or not in Python

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

Suppose we have a string s with some digits, we have to check whether it contains consecutively descending integers or not. So, if the input is like s = "99989796", then the output will be True, as this string is holding [99, 98, 97, 96] Algorithm To solve this, we will follow these steps: Define a function helper(). This will take pos, prev_num if pos is same as n, then return True num_digits := digit count of prev_num for i in range num_digits - 1 to num_digits, do if s[from index ...

Read More

Program to check we can visit any city from any city or not in Python

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

Suppose we have n cities represented as numbers in range [0, n) and we also have a list of one-way roads that connects one city to another. We have to check whether we can reach any city from any city or not. So, if the input is like n = 3, roads = [[0, 1], [0, 2], [1, 0], [1, 2], [2, 0], [2, 1]], then the output will be True, as you can go from any city to any other city through the available roads. Approach To solve this problem, we need to check if the ...

Read More

Program to check whether a binary tree is complete or not in Python

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

Suppose we have a binary tree; we have to check whether this is a complete binary tree or not. A complete binary tree is one where all levels are completely filled except possibly the last level, and all nodes in the last level are as far left as possible. So, if the input is like ? 9 7 10 ...

Read More

Program to count minimum number of operations to flip columns to make target in Python

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

Suppose we have a matrix M and a target matrix T with the same number of rows and columns. We can perform an operation where we flip a particular column in the matrix so that all 1s become 0s and all 0s become 1s. If we can reorder the matrix rows for free, we need to find the minimum number of operations required to turn M into T. If there is no solution, return -1. Problem Example Given matrices M and T ? Matrix M: 00 10 11 Target T: 01 10 11 ...

Read More

Program to count number of operations required to all cells into same color in Python

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

When we have a two-dimensional matrix where each cell contains a value representing its color, we need to find the minimum number of operations to make all cells the same color. Adjacent cells (top, bottom, left, right) with the same color form connected groups, and in each operation, we can change all cells in one group to any color. The key insight is that we should keep the color group with the most connected components unchanged, and convert all other groups to that color. Problem Understanding Given the matrix: 2 2 2 2 ...

Read More

Program to find largest sum of any path of a binary tree in Python

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

Suppose we have a binary tree, we have to find the largest sum of any path that goes from the root node to the leaf node. So, if the input is like ? 5 1 9 7 10 6 8 ...

Read More

Program to find circular greater element to the right in Python

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

The circular next greater element problem requires finding the next greater element to the right of each element in an array, with the array treated as circular. If no greater element exists, we assign -1. For example, given [4, 5, 1, 3], the result is [5, -1, 3, 4] because: 4's next greater element is 5 5 has no greater element, so -1 1's next greater element is 3 3's next greater element is 4 (wrapping around) Algorithm Steps We use a stack-based approach with double iteration to handle the circular nature: Initialize ...

Read More

Program to arrange cards so that they can be revealed in ascending order in Python

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

This problem involves arranging cards in a specific order so that when revealed using a particular pattern, they appear in ascending order. The revelation pattern is: remove the top card, then move the next card to the back, and repeat until no cards remain. Understanding the Problem Given cards [1, 2, 3, 4, 5, 6, 7, 8], we need to arrange them as [1, 5, 2, 7, 3, 6, 4, 8] so that the revelation process yields ascending order ? The revelation process works as follows: Remove top card (reveal it) Move the next top card ...

Read More

Program to partition two strings such that each partition forms anagram in Python

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

Suppose we have two non-empty strings s and t that are of the same length. We have to partition them into substrings such that each pair of s and t substring is the same size and they are anagrams of each other. Now find the cut indexes such that it results in the maximum number of cuts of s and t. If no result is found, then return empty list. So, if the input is like s = "bowcattiger" t = "owbactietgr", then the output will be [0, 3, 5, 6, 10], as we can partition the string into ...

Read More
Showing 1181–1190 of 3,768 articles
« Prev 1 117 118 119 120 121 377 Next »
Advertisements