Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 61 of 377

Program to generate first n lexicographic numbers in python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 388 Views

Suppose we have a number n, we have to find first n numbers that are sorted in lexicographic sequence.So, if the input is like n = 15, then the output will be [1, 10, 11, 12, 13, 14, 15, 2, 3, 4, 5, 6, 7, 8, 9]To solve this, we will follow these steps:count := 1ans := a list with single element countwhile size of ans < n, docount := count * 10while count > n , docount := quotient of count / 10count := count + 1while count mod 10 is same as 0, docount := quotient of count ...

Read More

Minimum Time to Collect All Apples in a Tree in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 520 Views

Suppose we have an undirected tree consisting of n vertices and these are numbered from 0 to n-1, which has some apples in their vertices. We spend 1 second to walk over one edge of the tree. We have to find the minimum time in seconds we have to spend in order to collect all apples in the tree starting at vertex 0 and coming back to this vertex.Here the edges of the undirected tree are given in the array edges, where edges[i] = [from_i, to_i] this means that exists an edge connecting the vertices from_i and to_i. Additionally, there ...

Read More

Simplified Fractions in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 443 Views

Suppose we have an integer n, we have to find a list of all simplified fractions between 0 and 1 (exclusive) such that the denominator

Read More

Program to find number not greater than n where all digits are non-decreasing in python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 348 Views

Suppose we have a number n, we have to find the largest number smaller or equal to n where all digits are non-decreasing.So, if the input is like n = 221, then the output will be 199.To solve this, we will follow these steps:digits := a list with all digits in nbound := nullfor i in range size of digits - 1 down to 0, doif digits[i] < digits[i - 1], thenbound := idigits[i - 1] := digits[i - 1] - 1if bound is not null, thenfor i in range bound to size of digits, dodigits[i] := 9join each digit ...

Read More

Program to find minimum number of deletions required from two ends to make list balanced in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 245 Views

Suppose we have a list containing 0s and 1s, we have to remove values from the front or from the back of the list. Finally, we have to find the minimum number of deletions required such that the remaining list has an equal number of 0s and 1s.So, if the input is like nums = [1, 1, 1, 0, 0, 1], then the output will be 2, as we can delete the first one 1 and last one 1 so that there's two 1s and two 0s.To solve this, we will follow these steps −longest := 0d := a map ...

Read More

Count Good Nodes in Binary Tree in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 503 Views

Suppose we have a binary tree, a node X in the tree is named good when in the path from root to X there are no nodes whose value is greater than X. Here we have to find the number of good nodes in the binary tree.So, if the input is like, then the output will be 4, the colored nodes are good node.To solve this, we will follow these steps −Define a function dfs(), this will take node, val, if node is null, then −returnret := ret + (1 when val left){          if(val != NULL) ...

Read More

Program to count number of fraction pairs whose sum is 1 in python

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

Suppose we have a list of fractions where each fraction is individual lists [numerator, denominator] which represents the number (numerator / denominator). We have to find the number of pairs of fractions whose sum is 1.So, if the input is like fractions = [[2, 7], [3, 12], [4, 14], [5, 7], [3, 4], [1, 4]], then the output will be 4, as (2/7 + 5/7), (3/12 + 3/4), (3/4 + 1/4), (4/14 + 5/7) are the four pairs which sum to 1.To solve this, we will follow these steps:d := a new mapans := 0for each fraction i in fractions, ...

Read More

Program to find minimum difference between two elements from two lists in Python

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

Suppose we have two lists L1 and L2, we have to find the smallest difference between a number from L1 and a number from L2.So, if the input is like L1 = [2, 7, 4], L2 = [16, 10, 11], then the output will be 3, as the smallest difference is 10 - 7 = 3.To solve this, we will follow these steps −sort the list L1 and sort the list L2ans := infinityi := 0, j := 0while i < size of L1 and j < size of L2, doans := minimum of ans and |L1[i] - L2[j]|if L1[i] ...

Read More

Rearrange Words in a Sentence in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 903 Views

Suppose we have a string with different words, that string is called sentence, and this is in the following format −First letter is in upper case.Each word in text are separated by a single space character.We have to rearrange the words in text such that all words are rearranged in increasing order of their lengths. If two words have the same length, arrange them in their original order.Then finally return the string by applying these rules.So, if the input is like "I love to code in cpp", then the output will be "I to in cpp love code"To solve this, ...

Read More

Program to find number of K-Length sublists whose average is greater or same as target in python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 291 Views

Suppose we have a list nums, and two additional values k and target, we have to find the number of sublists whose size is k and its average value ≥ target.So, if the input is like nums = [1, 10, 5, 6, 7] k = 3 target = 6, then the output will be 2, as the sublist [1, 10, 7] has average value of 6 and [10, 5, 6] has average of 7.To solve this, we will follow these steps:target := target * ksum := 0, ans := 0for each index i and number n in nums, doif i ...

Read More
Showing 601–610 of 3,768 articles
« Prev 1 59 60 61 62 63 377 Next »
Advertisements