Arnab Chakraborty has Published 4293 Articles

Shortest Path with Alternating Colors in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 11:16:31

672 Views

Suppose we have directed graph, with nodes labelled 0, 1, ..., n-1. In this graph, each edge is colored with either red or blue colors, and there could be self-edges or parallel edges. Each [i, j] in red_edges indicates a red directed edge from node i to node j. Similarly, ... Read More

Lowest Common Ancestor of Deepest Leaves in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 11:15:36

170 Views

Suppose we have a rooted binary tree, we have to return the lowest common ancestor of its deepest leaves. We have to keep in mind that −The node of a binary tree is a leaf node if and only if it has no childrenThe depth of the root of the ... Read More

Maximum Average Subtree in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 11:14:40

182 Views

Suppose we have the root of a binary tree; we have to find the maximum average value of any subtree of that tree. So if the tree is like −The output will be 6, this is because, for node 5, it will be (5 + 6 + 1)/ 3 = ... Read More

Deepest Leaves Sum in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 11:13:24

239 Views

Suppose we have a binary tree, we have to find the sum of values of its deepest leaves. So if the tree is like −Then the output will be 15.To solve this, we will follow these steps −Define a map m, and maxDepthDefine a recursive method solve(), this will take ... Read More

Maximum Number of Occurrences of a Substring in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 11:08:37

577 Views

Suppose we have a string s, we have to find the maximum number of occurrences of any substring that satisfies the following rules −The number of distinct characters in the substring must be less than or equal to maxLetters.The substring size must be in range minSize and maxSize inclusive.So if ... Read More

RLE Iterator in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 11:03:20

314 Views

Suppose we have to create an iterator that iterates through a run-length encoded sequence. Here the iterator is initialized by calling RLEIterator(int[] A), where A is a run-length encoding of a sequence. So we can say that for all even i, A[i] tells us the number of times that the ... Read More

Path In Zigzag Labelled Binary Tree in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 11:00:19

221 Views

Suppose in an infinite binary tree where every node has two children, the nodes are labelled in row order. Now in the odd numbered rows (the first, third, fifth, ...), the labelling is left to right, and in the even numbered rows (second, fourth, sixth, ...), the labelling is right ... Read More

Maximum Side Length of a Square with Sum Less than or Equal to Threshold in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 10:59:54

213 Views

Suppose we have a m x n matrix mat and an integer threshold. We have to the maximum side-length of a square with a sum less than or equal to the given threshold or return 0 if there is no such square. So if the input is like −113243211324321132432113243211324321132432And threshold ... Read More

Bitwise ORs of Subarrays in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 10:59:30

814 Views

Suppose we have an array A of non-negative integers. For every (contiguous) subarray say B = [A[i], A[i+1], ..., A[j]] (with i

The Earliest Moment When Everyone Become Friends in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 10:56:38

133 Views

Suppose in a social group, there are N different people, with unique integer ids from 0 to N-1. Here we have a list of logs, where each logs[i] = [time, id_A, id_B] contains a non-negative integer timestamp, and the ids of two different people. Each log is showing the time ... Read More

Advertisements