Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 101 of 377

Program to print maximum number of characters by copy pasting in n steps in Python?

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

Suppose we have a number n; we have to find the maximum number of characters we can enter using n operations where each operation is like: Inserting the character "x". Copy all characters. Paste So, if the input is like n = 12, then the output will be 81. Understanding the Problem This is a dynamic programming problem where we need to find the optimal strategy to maximize characters. The key insight is that after typing some characters, we should copy-paste to multiply them efficiently. The pattern involves: Type characters individually when ...

Read More

Program to count minimum number of operations required to make numbers non coprime in Python?

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

Two numbers are coprime if their greatest common divisor (GCD) is 1. This program finds the minimum number of increment/decrement operations needed to make two numbers non-coprime (GCD > 1). Problem Understanding Given two numbers A and B, we can perform operations to increment or decrement either number by 1. The goal is to find the minimum operations required so that GCD(A, B) ≠ 1. Example If A = 8 and B = 9, we can increment B to 10. Then GCD(8, 10) = 2, which is not 1, so they become non-coprime in just 1 ...

Read More

Program to find next state of next cell matrix state in Python?

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

This problem implements Conway's Game of Life, where we need to find the next state of a 2D binary matrix. A cell's neighbors are its immediate horizontal, vertical and diagonal cells (8 neighbors total). The rules are: Any living cell with two or three living neighbors survives Any dead cell with exactly three living neighbors becomes alive All other cells die or remain dead Example Input and Output Given this input matrix − ...

Read More

Program to remove all nodes with only one child from a binary tree in Python?

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

Suppose we have a binary tree root; we have to remove all nodes with only one child. A node with only one child is a node that has either a left child or a right child, but not both. So, if the input is like ? 1 2 3 4 5 ...

Read More

Program to find length of longest possible stick in Python?

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

Suppose we have a list of integers representing sticks. Each element in the list represents a stick with two ends, where values are between 1 and 6. We can connect two sticks together if any of their ends are the same. The resulting stick's ends will be the leftover ends and its length is increased. We have to find the length of the longest stick possible. So, if the input is like sticks = [[2, 3], [2, 4], [3, 5], [6, 6]], then the output will be 3. We can connect [2, 3] and [2, 4] to get [3, ...

Read More

Program to find a matrix for each condominium's height is increased to the maximum possible height in Python?

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

Suppose we have a 2D matrix where matrix[r][c] represents the height of a condominium in a city. The west-east skyline is visible by taking the maximum of each row in the matrix, and the north-south skyline can be visible by taking the maximum of each column. We have to find a new matrix where each condominium's height is increased to the maximum possible height while keeping the same west-east and north-south skyline. Understanding the Problem Given a matrix like this: 2 3 4 5 6 7 8 9 10 ...

Read More

Program to find sum of concatenated pairs of all each element in a list in Python?

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

Given a list of numbers, we need to find the sum of all possible concatenated pairs. Each pair (i, j) where i and j are indices is considered different from pair (j, i). For example, with nums = [5, 3], we get concatenations: 55, 53, 35, 33, which sum to 176. Algorithm We use memoization to avoid recalculating concatenations for duplicate numbers ? def find_concatenated_sum(nums): memo = {} total_sum = 0 n = len(nums) ...

Read More

Program to find length of concatenated string of unique characters in Python?

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

Given a list of strings, we need to find the maximum length of a concatenated string formed by selecting a subsequence of words where each character appears only once in the final string. The problem requires us to explore all possible combinations of words and find the one with maximum length that contains only unique characters. Algorithm Approach We use a recursive backtracking approach: For each word, we have two choices: include it or exclude it We can only include a word if it has unique characters and doesn't create duplicates when combined with our ...

Read More

Program to find maximum number of courses we can take based on interval time in Python?

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

Suppose we have a list of intervals in the form [start, end], representing the start and end time of courses. We need to find the maximum number of courses we can take, assuming we can only take one course at a time and the start of a course must be after the end of the previous course. So, if the input is like times = [[3, 6], [6, 9], [7, 8], [9, 11]], then the output will be 3, as we can take courses [[3, 6], [7, 8], [9, 11]]. Algorithm To solve this, we will follow ...

Read More

Program to find number of boxes that form longest chain in Python?

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

Suppose we have a list of boxes, where each entry has two values [start, end] (start < end). We can join two boxes if the end of one is equal to the start of another. We have to find the length of the longest chain of boxes. So, if the input is like boxes = [[4, 5], [5, 6], [4, 8], [1, 2], [2, 4]], then the output will be 4, as we can form the chain: [1, 2] → [2, 4] → [4, 5] → [5, 6] Algorithm To solve this, we will follow these steps ...

Read More
Showing 1001–1010 of 3,768 articles
« Prev 1 99 100 101 102 103 377 Next »
Advertisements