Deepest Left Leaf Node in a Binary Tree in C++

Hafeezul Kareem
Updated on 30-Dec-2020 06:36:43

279 Views

In this tutorial, we are going to find the deepest left leaf node in the binary tree. Let's see the binary tree.   A       B    C D       E       F                      GLet's see the steps to solve the problem.Write a Node struct with char, left, and right pointers.Initialize the binary tree with dummy data.Write a recursive function to find the deepest left node in the binary function. It takes three argument root node, isLeftNode, and result pointer to store the deepest node.If the ... Read More

Check if All Occurrences of a Character Appear Together in Python

Arnab Chakraborty
Updated on 29-Dec-2020 13:48:54

338 Views

Suppose we have a string s and another character c, we have to check whether all occurrences of c appear together in s or not. If the character c is not present in s then also return true.So, if the input is like s = "bbbbaaaaaaaccddd", c = 'a', then the output will be True.To solve this, we will follow these steps −flag := Falseindex := 0n := size of stringwhile index < n, doif string[index] is same as c, thenif flag is True, thenreturn Falsewhile index < n and string[index] is same as c, doindex := index + 1flag ... Read More

Check If All Enemies Are Killed with Bombs in a Matrix in Python

Arnab Chakraborty
Updated on 29-Dec-2020 13:46:49

177 Views

Suppose we have a matrix mat. There are few different values as follows The cells of matrix can hold any of these 3 characters0 for empty area.1 for bomb.2 for Enemies.Now bomb can blast in only horizontal and vertical directions from one end to another. We have to check whether all enemies will die when bomb explodes or not.So, if the input is like0020010002000010then the output will be True, because bomb at place [1, 1] can fill enemy at place [2, 1] and enemy at [0, 2] will be killed by bomb placed at [3, 2].To solve this, we will ... Read More

Check If All Elements of the Array Are Palindrome in Python

Arnab Chakraborty
Updated on 29-Dec-2020 13:45:18

2K+ Views

Suppose we have a list of numbers nums. We have to check whether the list is palindrome or not.So, if the input is like nums = [10, 12, 15, 12, 10], then the output will be True.To solve this, we will follow these steps −n := size of numsreset is_palindromei := 0while i

Check If All Digits of a Number Divide It in Python

Arnab Chakraborty
Updated on 29-Dec-2020 13:43:36

682 Views

Suppose we have a number n. We have to check whether all digits of it can divide n or not.So, if the input is like n = 135, then the output will be True, because (135 / 1 = 135), (135 / 3 = 45) and (135 / 5 = 27).To solve this, we will follow these steps −val := nwhile val > 0, dod := val mod 10if n is not divisible by d, thenreturn Falseval := quotient of (val / 10)return TrueLet us see the following implementation to get better understanding −Example Live Demodef is_divisible(n, d) :    return ... Read More

Check If a Two-Character String Can Be Made Using Given Words in Python

Arnab Chakraborty
Updated on 29-Dec-2020 13:36:45

161 Views

Suppose we have a string s of length 2, and also have a list of words w where all words are of length 2. We have to check whether we can concatenate words from w and that concatenated string contains s as substring or not.So, if the input is like s = "no", w = ["ol", "on", "ni", "to"], then the output will be True as we can concatenate strings like "onol", that contains "no"To solve this, we will follow these steps −n := the number of words in wchar_0 := False, char_1 := Falsefor i in range 0 to ... Read More

Check Triangle Area Possibility with Given Angles in Python

Arnab Chakraborty
Updated on 29-Dec-2020 13:28:56

903 Views

Suppose we have three angles. We have to check whether it is possible to create a triangle of positive area with these angles or not.So, if the input is like a = 40 b = 120 c = 20, then the output will be True as the sum of 40 + 120 + 20 = 180.To solve this, we will follow these steps −if a, b and c are not 0 and (a + b + c) is same as 180, thenif (a + b) >= c or (b + c) >= a or (a + c) >= b, thenreturn ... Read More

Check If a String is the Typed Name in Python

Arnab Chakraborty
Updated on 29-Dec-2020 13:27:45

526 Views

Suppose we have two lowercase strings s and t. Sometimes, when we type a vowel, the key might get long pressed, and the vowel will be repeated 1 or more times. We have to check whether it is possible that t is typed that indicates s or not.So, if the input is like s = "mine" t = "miiine", then the output will be True as vowel 'i' is repeated three times, other letters are fine.To solve this, we will follow these steps −s_len := size of st_len := size of tj := 0for i in range 0 to s_len ... Read More

Check If a String Is Suffix of Another in Python

Arnab Chakraborty
Updated on 29-Dec-2020 13:26:12

440 Views

Suppose we have two strings s and t. We have to check whether s is suffix of t or not.So, if the input is like s = "ate" t = "unfortunate", then the output will be True.To solve this, we will follow these steps −s_len := size of st_len := size of tif s_len > t_len, thenreturn Falsefor i in range 0 to s_len, doif s[s_len - i - 1] is not same as t[t_len - i - 1], thenreturn Falsereturn TrueLet us see the following implementation to get better understanding −Example Live Demodef solve(s, t):    s_len = len(s)   ... Read More

Check If a String Is Palindrome in C Using Pointers

Arnab Chakraborty
Updated on 29-Dec-2020 13:24:43

9K+ Views

Suppose we have a string s. We have to check whether the given string is a palindrome or not. We have to solve this problem using pointers in C.So, if the input is like s = "racecar", then the output will be True.To solve this, we will follow these steps −length := size of stringforward := pointing to the first character of stringreverse := pointing to the last character of stringwhile position of reverse >= position of forward, doif character pointed by reverse is same as character pointed by forward, thenincrease forward and decrease reverse by 1otherwisecome out from loopif ... Read More

Advertisements