Arnab Chakraborty has Published 4452 Articles

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

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Oct-2021 10:13:24

263 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 ... Read More

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

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Oct-2021 10:11:56

267 Views

Suppose we have an edge list where each items are holding (u, v) represents u is parent of v. We have to find the length of the longest path in the tree. The path length is 1 + number of nodes in that path.So, if the input is likethen the ... Read More

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

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Oct-2021 10:07:15

244 Views

Suppose we have a binary matrix. We can first rearrange the columns as many times as we want, then find return the area of the largest submatrix containing only 1s.So, if the input is like100111101then the output will be 4, because we can arrange is like −100111110To solve this, we ... Read More

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

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Oct-2021 10:03:28

157 Views

Suppose we have three values n, total, and k. Now consider a list of size n whose sum is same as total and where the absolute difference between any two consecutive elements is at most 1. We have to find the maximum value at index k of such a list.So, ... Read More

Program to find kth smallest element in linear time in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Oct-2021 10:01:16

1K+ Views

Suppose we have a list of numbers called nums, we also have another value k, we have to find the kth (starting from 0) smallest element in the list. We have to solve this problem in O(n) time on average.So, if the input is like nums = [6, 4, 9, ... 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 19-Oct-2021 09:59:09

807 Views

Suppose we have a list of numbers called counts where counts[i] represents the number of items are of type i. We also have another value k. We have to find the maximum number of groups of size k we can find, such that each group must have items of distinct ... Read More

Program to count how many blocks are covered k times by walking in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Oct-2021 13:28:47

227 Views

Suppose we have two lists called walks and target. At the beginning we are at position 0 in a one-dimensional line. Now |walks[i]| represents the number of steps have been walked. And when walk[i] is positive then indicates walked right, and negative for left. When we walk, we move one ... Read More

Program to count number of overlapping islands in two maps in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Oct-2021 13:26:26

112 Views

Suppose we have two binary matrices mat1 and mat2. Here 1 represents land and 0 represents water, if there is a group of 1(land) surrounded by water is called island. We have to find the number of islands that exist in both mat1 and mat2 at the exact same coordinates.So, ... Read More

Program to find index, where we can insert element to keep list sorted in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Oct-2021 13:18:29

538 Views

Suppose we have a list of numbers called nums, they are sorted in ascending order, we also have another number target, we have to find the index where target should be inserted to keep nums sorted. If target already present in nums, then return the largest index where target can ... Read More

Program to find how many updates required to make string half monotonous in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Oct-2021 13:15:56

109 Views

Suppose we have a lowercase string s whose length is even. We have to find the minimum number of characters that need to be updated such that one of the following three conditions is satisfied for all i, where 0 ≤ i < n/2 and j, n/2 ≤ j < ... Read More

Advertisements