Problem Statement: You are given an undirected graph, you need to check if the graph is a tree or not. Example In the below image, first graph is a tree, second graph is not a tree. Solution We know that an undirected graph is a tree …
Problem Statement: You are given 2 strings, you need to convert str1 to str2 by only moving a character from str1 to front. If the string can be transformed, then return the min number of operations required. Example Str 1 = ADCB Str 2 = ABCD …
Problem Statement: You are given a string, you need to find the length of longest proper perfix which is also a suffix. Example Example 1: ------------ str = "abcdabc" Output: 3 Here "abc" is the longest prefix suffix Example 2: -------------- str = "abcdef Output: …
Problem Statement: You are given a string S, you have to remove all the consecutive string. Example Input: aabb Output: ab Solution The solution is very simple and can be solved using recursion. Base case will be, if the string is empty return. else compare …
Problem Statement: You are given 2 strings s1 and s2. You need to find the smallest substring in s1 that has all the characters of s2. Example Input: s = "ARTYUIBANC", t = "ABC" Output: "BANC" Solution This problem can be solved by number of …
Problem Statement: You are given 3 words. You need to check if the summation of the letters lead up to third word. Example Input: s1 = "acb", s2 = "cba", s3 = "cdb" Output: true s1 = "acb" -> 0 2 1 s2 = "cba" …
Problem Statement: You are given a string, you need to check if ti is possible to rearrange the string such that no two adjacent characters are same. Example Input: aab Output: Yes Why? You can swap the string to "aba". So no 2 adjacent characters …
Problem Statement: You are given a word and series of dictionary. You need to check if the word can be broken down into multiple words that are present in the dictionary Example Dictionary { i, like, mobile, ice, cream, mango} Input: ilike Output: Yes The string …
Problem Statement: You are given a string, that contains only vowels and you need to get the longest substring that has all vowels “a’, ‘e’, ‘i’, ‘o’, ‘u’ in aplhabetical order. Example Input: word = "aeeeiiiioooauuuaeiou" Output: 5 Solution For this solution, we need to …