Arnab Chakraborty has Published 4293 Articles

Program to traverse binary tree level wise in alternating way in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 10-Oct-2020 10:54:23

141 Views

Suppose we have binary tree, we have to show the values of each level by alternating from going left-to-right and right-to-left.So, if the input is likethen the output will be [5, -10, 4, -2, -7, 15]To solve this, we will follow these steps −if root is null, thenreturn a new ... Read More

Program to find length of longest balanced subsequence in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 10-Oct-2020 10:47:50

371 Views

Suppose we have a string s containing brackets parenthesis "(" and ")", we have to find the length of the longest subsequence of balanced brackets.So, if the input is like s = "())(()(", then the output will be 4, as we can take the subsequence like "()()"To solve this, we ... Read More

Program to find the left side view of a binary tree in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 10-Oct-2020 10:43:56

110 Views

Suppose we have a binary tree, if we see the tree from left side, then we can see some elements of it. we have to display those elements. So if the tree is like −The output will be [1, 2, 5]To solve this, we will follow these steps −Define an ... Read More

Program to find leftmost deepest node of a tree in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 10-Oct-2020 10:34:00

379 Views

Suppose we have a binary tree; we have to find the value of the deepest node. If there are more than one deepest node, then return the leftmost deepest node.So, if the input is likethen the output will be 4 as 4 and 7 are deepest but 4 is left ... Read More

Program to check whether all leaves are at same level or not in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 10-Oct-2020 10:28:22

165 Views

Suppose we have a binary tree; we have to check whether all leaves are at the same level or not.So, if the input is likethen the output will be TrueTo solve this, we will follow these steps −Define a function dfs() . This will take root, dif root is not ... Read More

Program to check whether we can fill square where each row and column will hold distinct elements in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 09-Oct-2020 15:39:48

91 Views

Suppose we have one n × n matrix containing values from 0 to n. Here 0 represents an unfilled square, we have to check whether we can fill empty squares such that in each row and each column every number from 1 to n appears exactly once.So, if the input ... Read More

Program to find the largest sum of the path between two nodes in a binary tree in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 09-Oct-2020 15:29:23

239 Views

Suppose we have a binary tree; we have to find the maximum sum of any path between any two nodes.So, if the input is likethen the output will be 62 as the nodes are [12, 13, 14, 16, 7].To solve this, we will follow these steps −Define a function utils() ... Read More

Program to find largest sum of non-adjacent elements of a list in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 09-Oct-2020 15:18:41

879 Views

Suppose we have a list of numbers called nums, we will define a function that returns the largest sum of non-adjacent numbers. Here the numbers can be 0 or negative.So, if the input is like [3, 5, 7, 3, 6], then the output will be 16, as we can take ... Read More

Program to find sum of contiguous sublist with maximum sum in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 09-Oct-2020 15:15:29

988 Views

Suppose we have an array A. We have to find the contiguous sublist which has the maximum sum, and also return its sum. So if the array A is like A = [-2, 1, -3, 4, -1, 2, 1, -5, 4], then the sum will be 6. And the subarray ... Read More

Program to find the maximum sum of circular sublist in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 09-Oct-2020 15:04:22

259 Views

Suppose we have a list of numbers nums, now consider a circular list of nums where the start and end of nums are neighbors. We have to find the maximum sum of a non-empty sublist in the circular list.So, if the input is like nums = [2, 3, -7, 4, ... Read More

Advertisements