Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 8 of 377

Program to find length of longest substring with 1s in a binary string after one 0-flip in Python

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

Suppose we have a binary string s. We are allowed to flip at most one "0" to "1", we have to find the length of the longest contiguous substring of 1s. So, if the input is like s = "1010110001", then the output will be 4, as if we flip the zero present at index 3, then we get the string "1011110001", here length of the longest substring of 1s is 4. Algorithm To solve this, we will follow these steps ? n := size of s ans := ...

Read More

Program to find largest size to truncate logs to store them completely in database in Python

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

Suppose we have a list of numbers called logs and another value limit. Each element in logs[i] represents the size of logs generated by the i-th user. The limit represents the total size of logs we can store in our database. We need to find the largest x such that if we truncate every log in logs to be at most size x, the sum of the truncated log sizes is at most limit. If no log needs to be truncated, then simply return the largest log size. So, if the input is like logs = [500, 200, 10000, ...

Read More

Program to find minimum length of first split of an array with smaller elements than other list in Python

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

Suppose we have a list of numbers nums, we want to split the list into two parts part1 and part2 such that every element in part1 is less than or equal to every element in part2. We have to find the smallest length of part1 that is possible (not 0 length). So, if the input is like nums = [3, 1, 2, 5, 4], then the output will be 3, because we can split the list like part1 = [3, 1, 2] and part2 = [5, 4]. Algorithm Approach To solve this problem, we follow these steps ...

Read More

Program to count number of on lights flipped by n people in Python

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

Suppose we have n toggle switches in a room and n people present in that room. They flip switches according to a specific pattern: Person 1 comes and flips all switches (1, 2, 3, 4, ...) Person 2 comes and flips switches that are multiples of 2 (2, 4, 6, 8, ...) Person i comes and flips switches that are multiples of i We need to find how many switches will be in the ON position after all n people have finished flipping. Understanding the Problem ...

Read More

Program to find lexicographically smallest lowercase string of length k and distance n in Python

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

Suppose we have two numbers n and k. We have to find the lexicographically smallest lowercase string of size k and distance n. The distance is the sum of the letter number in alphabet. For example, 'a' has letter number 1, 'b' has 2, 'y' has 25, 'z' has 26 and so on. So, if the input is like n = 15 k = 3, then the output will be "aam", because "aam" is the lexicographically smallest string of length 3 whose distance is 1 + 1 + 13 = 15. Algorithm To solve this, we will ...

Read More

Program to find length of the longest path in an n-ary tree in Python

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

In this problem, we need to find the longest path in an n-ary tree represented by an edge list. Each edge (u, v) indicates that u is the parent of v. The path length is calculated as 1 + number of nodes in the path. For the given tree structure: 1 ...

Read More

Program to find area of largest submatrix by column rearrangements in Python

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

Suppose we have a binary matrix. We can rearrange the columns as many times as we want, then find the area of the largest submatrix containing only 1s. So, if the input is like ? 1 0 0 ...

Read More

Program to find largest kth index value of one list in Python

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

Given three values n, total, and k, we need to find the maximum value at index k in a list of size n. The list must satisfy two conditions: its sum equals total, and the absolute difference between consecutive elements is at most 1. So, if the input is like n = 5, total = 15, k = 3, then the output will be 4, because one possible list is [3, 2, 3, 4, 3], where the maximum element at index 3 is 4. Algorithm Steps To solve this, we will follow these steps − ...

Read More

Program to find kth smallest element in linear time in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 2K+ Views

Finding the kth smallest element in a list is a common problem that can be solved efficiently using heap data structures. The challenge is to achieve O(n) average time complexity rather than the naive O(n log n) sorting approach. So, if the input is like nums = [6, 4, 9, 3, 1] and k = 2, then the output will be 4. After sorting, the list becomes [1, 3, 4, 6, 9], where the 2nd smallest element (0-indexed) is 4. Algorithm Steps To solve this efficiently, we will follow these steps − Create a max ...

Read More

Program to find maximum number of K-sized groups with distinct type items are possible in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 1K+ Views

Suppose we have a list of numbers called counts where counts[i] represents the number of items of type i. We also have another value k. We have to find the maximum number of groups of size k we can form, such that each group must have items of distinct types. So, if the input is like counts = [2, 3, 5, 3] and k = 2, then the output will be 6. Let four types of items be represented by a, b, c, d respectively. We can have the following groups of k = 2, where all elements are ...

Read More
Showing 71–80 of 3,768 articles
« Prev 1 6 7 8 9 10 377 Next »
Advertisements