Arnab Chakraborty has Published 4293 Articles

All Possible Full Binary Trees in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 10:34:58

329 Views

Suppose a full binary tree is a binary tree where each node has exactly 0 or 2 children. So we have to find a list of all possible full binary trees with N nodes. Each node of each tree in the answer must have node.val = 0. The returned trees ... Read More

Length of Longest Fibonacci Subsequence in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 10:33:46

154 Views

Suppose we have a sequence X_1, X_2, ..., X_n is fibonacci-like if −n >= 3X_i + X_{i+1} = X_{i+2} for all i + 2 = 3 otherwise return 0.Let us see the following implementation to get better understanding −Example Live Demo#include using namespace std; class Solution {    public:   ... Read More

Smallest Subtree with all the Deepest Nodes in C++

Arnab Chakraborty

Arnab Chakraborty

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

162 Views

Suppose we have a binary tree rooted at root, the depth of each node is the shortest distance to the root. Here a node is deepest if it has the largest depth possible among any node in the entire tree. The subtree of a node is that node, plus the ... Read More

Maximum Binary Tree in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 10:31:49

637 Views

Suppose we have an integer array. All elements in that array is unique. A maximum tree building on this array is defined as follow −The root will hold the maximum number in the array.The left subtree is the maximum tree constructed from left side of the subarray divided by the ... Read More

Find Largest Value in Each Tree Row in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 10:27:57

192 Views

Suppose we have a binary tree, we have to find the largest elements of each level of that tree. So if the tree is like −Then the output will be [3, 5, 8]To solve this, we will follow these steps −Define an array called ansdefine a recursive function solve(), this ... Read More

Prime Palindrome in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 10:27:11

1K+ Views

Suppose we have to find the smallest prime palindrome that is greater than or equal to N. So if the N is 13, then the smallest palindrome will be 101.To solve this, we will follow these steps −If N is in range 8 to 11, then return 11for i in ... Read More

Find Bottom Left Tree Value in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 10:25:32

240 Views

Suppose we have a binary tree. We have to find the left most value of the last row of that tree. So if the tree is like −Then the output will be 7, as the last row is [7, 4], and left most element is 7.To solve this, we will ... Read More

Most Frequent Subtree Sum in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 10:24:15

318 Views

Suppose we have the root of a tree, we have to find the most frequent subtree sum. The subtree sum of a node is actually the sum of all the node values formed by the subtree rooted at that node (including the node itself). The most frequent subtree sum is ... Read More

Score After Flipping Matrix in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 10:22:45

169 Views

Suppose we have a two dimensional matrix A where each value is 0 or 1. Here a move consists of choosing any row or column, and toggling each value in that row or column: changing all 0s to 1s, and all 1s to 0s. Now after making any number of ... Read More

Circular Array Loop in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 10:16:09

3K+ Views

Suppose we have a circular array nums of positive and negative integer values. If a number k at an index is a positive number, then move forward k steps. Otherwise, if it's negative (-k), move backward k steps. Since the array is circular, we can assume that the next element ... Read More

Advertisements