Arnab Chakraborty has Published 3734 Articles

Walls and Gates in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Nov-2020 11:56:50

618 Views

Suppose we have one m x n 2D grid, and that is initialized with these three possible values.-1 for a wall or an obstacle.0 for a gate.INF This is infinity means an empty room.Here 2^31 - 1 = 2147483647 is INF as we may assume that the distance to a ... Read More

Inorder Successor in BST in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Nov-2020 11:53:50

235 Views

Suppose we have a binary search tree and a node in it, we have to search the in-order successor of that node in the BST. As we know that the successor of a node p is the node with the smallest key greater than p.val.So, if the input is like ... Read More

Zigzag Iterator in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Nov-2020 11:51:10

326 Views

Suppose there are two 1D arrays, we have to implement an iterator that will return their elements alternately. There will be two methods −next() − to get next elementhasNext() − to check whether the next element is present or not.So, if the input is like v1 = [1, 2] v2 ... Read More

Find the Celebrity in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Nov-2020 11:46:42

231 Views

Suppose we have n people (labeled from 0 to n - 1) and among them, there may exist one celebrity. We can say a person x is a celebrity when all the other n - 1 people know x but x does not know any of them. Here we have ... Read More

Encode and Decode Strings in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Nov-2020 11:44:30

6K+ Views

Suppose we have a list of strings. We have to design an algorithm that can encode the list of strings to a string. We also have to make one decoder that will decode back to the original list of strings. Suppose we have the encoder and decoder installed on these ... Read More

Palindrome Permutation II in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Nov-2020 11:41:53

266 Views

Suppose we have a string s, we have to find all the palindromic permutations of it, there will be no repetition. If no palindromic permutation is there, then simply return empty string.So, if the input is like "aabb", then the output will be ["abba", "baab"]To solve this, we will follow ... Read More

Graph Valid Tree in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Nov-2020 11:39:10

368 Views

Suppose we have n nodes they are labeled from 0 to n-1 and a list of undirected edges [u, v], We have to define a function to check whether these edges make up a valid tree or not.So, if the input is like n = 5, and edges = [[0, ... Read More

Factor Combinations in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Nov-2020 11:33:01

332 Views

Suppose we have a number. The numbers can be regarded as a product of its factors. So, 8 = 2 x 2 x 2; = 2 x 4. We have to make one function that takes an integer n and return all possible combinations of its factors.So, if the input ... Read More

Meeting Rooms II in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Nov-2020 11:30:42

1K+ Views

Suppose there is an array of meeting time intervals. There are two times start and end times [[s1, e1], [s2, e2], ...] and each pair satisfies the rule (si < ei), We have to find the minimum number of conference rooms required.So, if the input is like [[0, 30], [5, ... Read More

Flatten 2D Vector in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Nov-2020 11:28:57

865 Views

Suppose we have a 2D vector, we have to design and implement an iterator to flatten that 2d vector. There will be different methods as follows −next() − This will return the next element of the current elementhasNext() − This will check whether next element is present or notSo, if ... Read More

Advertisements