Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 199 of 377

Count Triplets That Can Form Two Arrays of Equal XOR in C++

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

Suppose we have an array of integers arr. We want to select three indices like i, j and k where (0 = 0; j--) {             x1 = x1 ^ arr[j];             m[x1]++;          }          for (int j = i; j < n; j++) {             x2 = x2 ^ arr[j];             ret += m[x2];          }       }       return ret;    } }; main(){    Solution ob;    vector v = {2,3,1,6,7};    cout

Read More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 529 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 458 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

Count Good Nodes in Binary Tree in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 511 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

Rearrange Words in a Sentence in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 921 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

People Whose List of Favorite Companies Is Not a Subset of Another List in C++

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

Suppose we have an array called favorite companies where favoriteCompanies[i] is the list of favorites companies of the ith person. We have to find the indices of people whose list of favorite companies is not a subset of any other list of favorites companies.So, if the input is like favoriteCompanies = [["TCS", "google", "facebook"], ["google", "microsoft"], ["google", "facebook"], ["google"], ["amazon"]], then the output will be [0, 1, 4], this is because person with index=2 has ["google", "facebook"] which is a subset of favoriteCompanies[0]= ["TCS", "google", "facebook"] corresponding to the person with index 0.Now person with index=3 has ["google"] which is ...

Read More

Maximum Number of Vowels in a Substring of Given Length in C++

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

Suppose we have a string s and an integer k. We have to find the maximum number of vowel letters in any substring of s with length k.So, if the input is like s = "abciiidef", k = 3, then the output will be 3To solve this, we will follow these steps −cnt := 0Define one set mfor each vowel v, doinsert v into mret := 0for initialize i := 0, when i < k, update (increase i by 1), do −cnt := cnt + (1 when s[i] is in m, otherwise 0)ret := maximum of ret and cntn := ...

Read More

Pseudo-Palindromic Paths in a Binary Tree in C++

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

Suppose we have a binary tree where node values are digits from 1 to 9. One path in the binary tree is said to be pseudo-palindromic when at least one permutation of the node values in the path is a palindrome. We have to find the number of pseudo-palindromic paths going from the root node to leaf nodes.So, if the input is likethen the output will be 2, this is because there are three paths going from the root node to leaf nodes − red path follows [2, 3, 3], the green path follows [2, 1, 1], and the path ...

Read More

Course Schedule IV in C++

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

Suppose there are a total of n courses we can to take, the courses are labeled from 0 to n-1.Some courses may have direct prerequisites, as example, to take course 0 we have first to take course 1, which is expressed as a pair: [1, 0].So, if we have a number of courses n, a list of direct prerequisite pairs and a list of queries pairs.You should find the answer for each queries[i] whether the course queries[i][0] is a prerequisite of the course queries[i][1] or not. Finally, we have to return a list of boolean, the answers to the given ...

Read More

Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts in C++

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

Suppose we have a rectangular cake with height h and width w, we also have two arrays of integers horizontalCuts and verticalCuts where horizontalCuts[i] represents the distance from the top of the rectangular cake to the ith horizontal cut and similarly, verticalCuts[j] represents distance from the left of the rectangular cake to the jth vertical cut.We have to find the maximum area of a piece of cake after we cut it at each horizontal and vertical position provided in the arrays horizontalCuts and verticalCuts. The answer may be large, so return this modulo 10^9 + 7.So, if the input is ...

Read More
Showing 1981–1990 of 3,768 articles
« Prev 1 197 198 199 200 201 377 Next »
Advertisements