Arnab Chakraborty has Published 3734 Articles

Count Univalue Subtrees in C++

Arnab Chakraborty

Arnab Chakraborty

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

337 Views

Suppose we have a binary tree; we have to count the number of uni-value subtrees. Here the Uni-value subtree indicates all nodes of the subtree have the same value.So, if the input is like root = [5, 1, 5, 5, 5, null, 5], then the output will be 4To solve ... Read More

Group Shifted Strings in C++

Arnab Chakraborty

Arnab Chakraborty

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

252 Views

Suppose we have a string, we can "shift" each of its letter to its successive letter, so: "abc" can be changed to "bcd". We can keep doing this operation which forms the sequence: "abc" -> "bcd" -> ... -> "xyz". If we have a list of non-empty strings that contains ... Read More

Strobogrammatic Number II in C++

Arnab Chakraborty

Arnab Chakraborty

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

522 Views

Suppose we have a length n. We have to find all strobogrammatic numbers that are of length n.As we know that a strobogrammatic number is a number that looks the same when rotated 180 degrees.So, if the input is like n = 2, then the output will be ["11", "69", ... Read More

Shortest Word Distance II in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Nov-2020 11:17:13

447 Views

Suppose there is a class that receives a list of words in the constructor, there will be a method that takes two words word1 and word2 and find the shortest distance between these two words in the list. That method will be called repeatedly many times with different parameters.Let us ... Read More

Missing Ranges in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Nov-2020 11:13:29

292 Views

Suppose we have a sorted integer array nums, the range of elements are in the inclusive range [lower, upper], we have to find the missing ranges.So, if the input is like nums = [0, 1, 3, 50, 75], and lower value is 0 and upper value is 99, then the ... Read More

One Edit Distance in C++

Arnab Chakraborty

Arnab Chakraborty

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

219 Views

Suppose we have two strings s and t; we have to check whether they are both one edit distance apart. The one edit distance has three types −Insert a character into s to get tDelete a character from s to get tReplace a character of s to get tSo, if ... Read More

Longest Substring with At Most Two Distinct Characters in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Nov-2020 11:09:04

1K+ Views

Suppose we have a string s; we have to find the length of the longest substring t that has at most 2 distinct characters.So, if the input is like "eceba", then the output will be 3 as t is "ece" which its length is 3.To solve this, we will follow ... Read More

Binary Tree Upside Down in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Nov-2020 11:07:24

366 Views

Suppose we have a binary tree where all the right nodes are either leaf nodes with a sibling otherwise empty, we have to flip it upside down and turn it into a tree where the original right nodes turned into left leaf nodes. We have to return the new node.So, ... Read More

Synonymous Sentences in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Nov-2020 11:03:31

493 Views

Suppose we have a list of pairs of equivalent words synonyms and a sentence text, we have to find all possible synonymous sentences they are sorted lexicographically.So, if the input is like synonyms = [["happy", "joy"], ["sad", "sorrow"], ["joy", "cheerful"]], and text = "I am happy today but was sad ... Read More

Campus Bikes II in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 18-Nov-2020 10:59:02

320 Views

Suppose we have a 2D grid, that represents a campus, there are N workers and M bikes, The value of N

Advertisements