Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 37 of 377

Program to find out the number of accepted invitations in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 420 Views

This is a bipartite matching problem where we need to find the maximum number of boy-girl pairs for a party. Each boy can invite multiple girls, but each girl can accept only one invitation. We'll use a depth-first search (DFS) approach to solve this matching problem. Problem Understanding Given an m × n matrix where m boys invite n girls: Matrix[i][j] = 1 means boy i sent an invitation to girl j Matrix[i][j] = 0 means no invitation was sent Each girl can accept at most one invitation We need to find the maximum number of ...

Read More

Program to find out the number of pairs of equal substrings in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 409 Views

Suppose we are given two strings, both made of lowercase alphabets. We have to find out the number of quadruples (p, q, r, s) satisfying the given conditions − 0

Read More

Program to sort out phrases based on their appearances in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 187 Views

Suppose we are given two lists: phrases that contains selected phrases and sentences that contains several sentences. We need to find which phrases appear in the sentences and sort the phrases based on their frequency of appearances. The phrase with the most appearances comes first. So, if the input is like phrases = ['strong', 'durable', 'efficient'], sentences = ['the product is durable and efficient', 'strong and durable', 'it is efficient', 'like it because it is efficient'], then the output will be ['efficient', 'durable', 'strong'] The phrase 'efficient' appears in 3 sentences (indices 0, 2, and 3), making it ...

Read More

Program to find out the buildings that have a better view in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 378 Views

Suppose, we are provided with an array that contains the heights of different buildings. The buildings are located on a line, and a building has a better view if it is not obstructed by another taller building. So provided the array containing heights, we have to find out the buildings that do not have other taller buildings to obstruct the view from them. The indices are returned from the array that satisfies the criteria. So, if the input is like height = [5, 6, 8, 7], then the output will be [2, 3]. The buildings in array index 0 ...

Read More

Program to design a queue that moves the most recently used element to the end of it in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 516 Views

We need to design a queue that moves the most recently used element to the end. The queue is initialized with integers 1 to n, and we implement a function that moves an element from a given position to the end while returning that element's value. For example, with n = 5 (queue contains [1, 2, 3, 4, 5]) and move operations at positions 5, 2, 3, and 1, the output will be 5, 2, 4, 1 respectively. Algorithm Steps To solve this efficiently, we use a square root decomposition approach − Find the correct ...

Read More

Program to find out the sum of the maximum subarray after a operation in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 246 Views

Given an array of integers, we can perform one operation where we replace any element array[i] with its squared value array[i] * array[i]. Our goal is to find the maximum possible subarray sum after performing this operation. So, if the input is like array = [4, 1, -2, -1], then the output will be 17. If we replace the value in array[0] with its squared value, the array becomes [16, 1, -2, -1]. The maximum subarray from this is [16, 1], which has the sum 16 + 1 = 17. Algorithm We use dynamic programming with ...

Read More

Program to restore the array from adjacent pairs in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 310 Views

Suppose we have a 2D array called adPair of size n-1 where each adPair[i] has two elements [ui, vi] representing that the elements ui and vi are adjacent in an array called nums. In nums there are n unique elements. We have to find the array nums. So, if the input is like adPair = [[3, 2], [4, 5], [4, 3]], then the output will be [2, 3, 4, 5]. Algorithm To solve this, we will follow these steps ? my_map := an empty map to store adjacency list for different ...

Read More

Program to find out distance between two nodes in a binary tree in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 862 Views

Suppose, we are given a binary tree and are asked to find the distance between two nodes in the binary tree. We find out the edges between the two nodes like in a graph and return the number of edges or the distance between them. A node of a tree has the structure as below − data : right : left : So, if the input is like 5 ...

Read More

Program to find k-th largest XOR coordinate value in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 233 Views

Suppose we have one m x n matrix and another value k. The value of coordinate (a, b) of the matrix is the XOR of all matrix[i, j] where i is in range (0 to a) and j is in range (0 to b). We have to find the k-th largest value (1-indexed) of all the coordinates of the matrix. Problem Example Consider the following matrix: 5 2 1 6 If k = 1, then the output will be 7 because the value of coordinate (0, 1) is 5 XOR ...

Read More

Program to change minimum characters to satisfy one of three conditions in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 236 Views

Suppose we have two strings s and t with only lowercase letters. In one operation, we can change any character in s or t to any lowercase letter. We have to satisfy one of the following three conditions ? Every letter in s is strictly smaller than every letter in t in the alphabet. Every letter in t is strictly smaller than every letter in s in the alphabet. Both s and t consist of only one distinct letter. We have to find the minimum number of ...

Read More
Showing 361–370 of 3,768 articles
« Prev 1 35 36 37 38 39 377 Next »
Advertisements