Find Longest Bitonic Sequence from Two Different Arrays in C++

Arnab Chakraborty
Updated on 24-Jul-2020 11:58:21

211 Views

ConceptWith respect of given two arrays, our task to determine the longest possible bitonic sequence so that increasing part must be from first array and should be a subsequence of first array. In the same way, decreasing part of must be from second array and should be a subsequence of it.Inputarr1[] = {2, 6, 3, 5, 4, 6}, arr2[] = {9, 7, 5, 8, 4, 3}Output2, 3, 4, 6, 9, 7, 5, 4, 3Inputarr1[] = {3, 1, 2, 4, 5}, arr2[] = {6, 4, 3, 2}Output1, 2, 4, 5, 6, 4, 3, 2MethodSo the concept is to implement longest increasing ... Read More

Find Longest Palindrome Formed by Removing or Shuffling Chars from String in C++

Arnab Chakraborty
Updated on 24-Jul-2020 11:56:17

221 Views

ConceptWith respect of a given string, determine the longest palindrome that can be formed by removing or shuffling characters from the string. Finally return only one palindrome if it hasbeen observed that there is multiple palindrome strings of longest length.InputpqrOutputp OR q OR rInputppqqrrOutputpqrrqp OR qprrpq OR rqppqr OR any other palindromic string of length 6.InputpqpOutputpqpMethodHere, We can partition any palindromic string into three parts – beg, mid and end. With respectof palindromic string of odd length say 2n + 1, here ‘beg’ consists of first n characters of the string, ‘mid’ consists of only 1 character that means (n ... Read More

Find K-th Character of Decrypted String in C++ - Set 2

Arnab Chakraborty
Updated on 24-Jul-2020 11:45:39

192 Views

ConceptWith respect of a given encoded string where repetitions of substrings are indicated as substring followed by count of substrings. So, for example, if encrypted string is “pq2rs2” and k=5, so output will be ‘r’ because decrypted string is “pqpqrsrs” and 5th character is ‘r’.It should be noted that frequency of encrypted substring can be of more than one digit. So, for example, in “pq12r3”, pq is repeated 12 times. Here, no leading 0 is present in frequency of substring.Input"p2q2r3", k = 6OutputrDecrypted string is "ppqqrrr"Input"pq4r2ts3", k = 11OutputtDecrypted string is "pqpqpqpqrrtststs"MethodHere, the stepwise algorithm is −Determine length of current ... Read More

Find Indexes of 0 to Replace with 1 for Longest Continuous Sequence of 1s in C++

Arnab Chakraborty
Updated on 24-Jul-2020 11:37:24

172 Views

ConceptWith respect of a given array of 0s and 1s, determine the position of 0 to be replaced with 1 to get maximum continuous sequence of 1s. In this case, expected time complexity is O(n) and auxiliary space is O(1).Inputarr[] = {1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1}OutputIndex 10Let array index starts from 0, replacing 0 with 1 atindex 10 causes the longest continuous sequence of 1s.Inputarr[] = {1, 1, 1, 1, 1, 0}OutputIndex 5MethodUsing count of ones on both sides of zero −Now, the concept is to count number of ones on both ... Read More

Find Index i for Palindrome Concatenation in C++

Arnab Chakraborty
Updated on 24-Jul-2020 11:33:42

179 Views

ConceptWith respect of given two strings S1 and S2 of equal lengths, our task is to determine an index i such that S1[0…i] and S2[i+1…n-1] give a palindrome when concatenated together. Ithas been seen that if it is not possible to determine such an index then print -1.InputS1 = “pqrsu”, S2 = “wxyqp”Output1S1[0..1] = “pq”, S2[2..n-1] = “ypq”S1 + S2 = “pqyqp” indicates is a palindrome.InputS1 = “pqrst”, S2 = “qprqz”Output-1MethodAt first, we iterate from 0 to n (length of the string) and copy ith character from S1 to another string (assume it is S).After that we take another temporary ... Read More

Path of More Than K Length from Source in C++

Arnab Chakraborty
Updated on 24-Jul-2020 11:28:25

179 Views

ConceptWith respect of a given graph, a source vertex in the graph and a number k(here k indicates the path length of graph between source vertex and destination vertex), our task is to determine if there is a simple path (without any cycle) beginning from given source and ending at any other vertex(i.e. destination). The graph is shown in following −InputSource s = 0, k = 64OutputTrueThere exists a simple path 0 -> 7 -> 1-> 2 -> 8 -> 6 -> 5 -> 3 -> 4, which has a total distance of 68 km which is more than 64.InputSource ... Read More

Neat Arrangement of Cups and Shelves in C++

Arnab Chakraborty
Updated on 24-Jul-2020 11:23:06

147 Views

ConceptWith respect of given three different types of cups (p[]) and saucers (q[]), and m numberof shelves, determine if neat arrangement of cups and shelves can be made.Now, arrangement of the cups and saucers will be neat if it follows the following rules −According to first rule, no shelf can contain both cups and saucers.According to second rule, there can be no more than 5 cups in any shelf.According to third rule, there can be no more than 10 saucers in any shelf.Inputp[] = {4, 3, 7} q[] = {5, 9, 10} m = 11OutputYesExplanationTotal cups = 14, shelves required ... Read More

Get Ratio from Given Ranges of Costs and Quantities in C++

Arnab Chakraborty
Updated on 24-Jul-2020 11:22:07

113 Views

ConceptWith respect of the given range of cost from lowCost to upCost and range of quantity from lowQuant to upQuant, determine if it is possible to obtain a given ratio r where r=cost/quantity, and lowCost

Check if Vertical Level of Binary Tree is Sorted in C++

Arnab Chakraborty
Updated on 24-Jul-2020 11:20:26

142 Views

ConceptWith respect of a given binary tree, our task is to determine if a given vertical level of the binary tree is sorted or not.(With respect of this case, when two nodes are overlapping, verify if they form a sorted sequence in the level they lie.)Input2 / \ 3 6 / \ 8 5   / 7 Level l = -1OutputYesNodes in level -1 are 3 -> 7 which form a sorted sequence.Input2 / \ 3 7 \ / 4 5 Level l = 0OutputYesIt should be noted that nodes with value 4 and 5 are overlapping in the binary ... Read More

Find Independent Set of Given Size in Undirected Graph using C++

Arnab Chakraborty
Updated on 24-Jul-2020 11:17:08

173 Views

ConceptWith respect of a given undirected graph, verify if it contains an independent set of size l. If there exists an independent set of size l print ‘Yes’, else print ‘No’. It should be noted that an independent set in a graph is defined as a set of vertices which are not directly connected to each other.InputL = 4, graph = [[1, 0, 1, 0, 0], [0, 1, 1, 0, 0], [1, 1, 1, 1, 1], [0, 0, 1, 1, 0], [0, 0, 1, 0, 1]];OutputYesThe above graph contains an independent set of size 4 (vertices 0, 1, 3, 4 ... Read More

Advertisements