Arnab Chakraborty has Published 4293 Articles

Program to remove all nodes of a linked list whose value is same as in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 06-Oct-2020 06:08:18

415 Views

Suppose we have a singly linked list, and one target, we have to return the same linked after deleting all nodes whose value is same as target.So, if the input is like [5, 8, 2, 6, 5, 2, 9, 6, 2, 4], then the output will be [5, 8, 6, ... Read More

Program to find Lexicographically Smallest String With One Swap in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 06-Oct-2020 06:06:36

3K+ Views

Suppose we have a string s, we have to find the lexicographically smallest string that can be made if we can make at most one swap between two characters in the given string s.So, if the input is like "zyzx", then the output will be "xyzz"To solve this, we will ... Read More

Program to check whether a binary tree is BST or not in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 06-Oct-2020 05:59:22

665 Views

Suppose we have binary tree; we have to check whether it is a binary search tree or not. As we know a BST has following properties −all nodes on its left subtree is smaller than current node valueall nodes on its right subtree is larger than current node valuethese properties ... Read More

Program to remove all nodes from BST which are not in range in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 06-Oct-2020 05:56:14

197 Views

Suppose we have a BST, an two values low and high, we have to delete all nodes that are not between [low, high] (inclusive).So, if the input is likelow = 7 high = 10, then the output will beTo solve this, we will follow these steps −Define a function solve() ... Read More

Program to check whether different brackets are balanced and well-formed or not in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 06-Oct-2020 05:53:03

277 Views

Suppose we have a string of brackets (round, curly, and square), we have to check whether the brackets are balanced (well-formed) or not.So, if the input is like s = "([()()]{[]})()", then the output will be TrueTo solve this, we will follow these steps −stack := a new listd := ... Read More

Program to check whether parentheses are balanced or not in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 06-Oct-2020 05:49:35

268 Views

Suppose we have a string s consisting of parenthesis "(" and ")". We have to check whether the parentheses are balanced or not.So, if the input is like s = "(()())(())", then the output will be TrueTo solve this, we will follow these steps −num_open := 0for each character c ... Read More

Program to find contiguous intervals of a unique array in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 05-Oct-2020 14:58:01

689 Views

Suppose we have a list of unique numbers called nums. We have to find a sorted 2D matrix of numbers where each list represents an inclusive interval summarizing number that are contiguous in nums.So, if the input is like nums = [10, 11, 12, 15, 16, 17, 28, 30], then ... Read More

Program to check string contains consecutively descending string or not in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 05-Oct-2020 14:42:50

309 Views

Suppose we have a string s with some digits, we have to check whether it contains consecutively descending integers or not.So, if the input is like s = "99989796", then the output will be True, as this string is holding [99, 98, 97, 96]To solve this, we will follow these ... Read More

Program to check we can visit any city from any city or not in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 05-Oct-2020 14:25:52

803 Views

Suppose we have n cities represented as a number in range [0, n) and we also have a list of one-way roads that connects one city to another. We have to check whether we can reach any city from any city.So, if the input is like n = 3, roads ... Read More

Program to check whether a binary tree is complete or not in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 05-Oct-2020 14:17:57

467 Views

Suppose we have a binary tree; we have to check whether this is a complete binary tree or not. As we know in a complete binary tree the levels are filled with nodes except possibly the last and all nodes in the last level are as far left as possible.So, ... Read More

Advertisements