
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7197 Articles for C++

201 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

567 Views
Suppose we have a binary search tree and a value K as input, we have to find K-th smallest element in the tree.So, if the input is likek = 3, then the output will be 15.To solve this, we will follow these steps −Define a function find_kth_smallest(), this will take root, count, k, if root is NULL, then −return NULLleft = find_kth_smallest(left of root, count, k)if left is not NULL, then −return left(increase count by 1)if count is same as k, then −return rootreturn find_kth_smallest(right of root, count, k)From the main method, do the following −count := 0res = find_kth_smallest(root, ... Read More

183 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

230 Views
Suppose we have a list of N jobs where each job has three parameters. 1. Start Time 2. Finish Time 3. Profit We have to find a subset of jobs associated with maximum profit so that no two jobs in the subset overlap.So, if the input is like N = 4 and J = {{2, 3, 55},{4, 6, 25},{7, 20, 150},{3, 150, 250}} , then the output will be [(2, 3, 55),(3, 150, 250)] and optimal profit 305To solve this, we will follow these steps −Define a function find_no_conflict(), this will take an array jobs, index,left := 0, right := index - 1while left

187 Views
Suppose we have a list of tickets represented by pairs of departure and arrival airports like [from, to], we have to find the itinerary in order. All of the tickets belong to a man who departs from Chennai. So, the itinerary must begin with Chennai.So if the input is like [["Mumbai", " Kolkata"], ["Chennai ", " Mumbai"], ["Delhi", "Bangalore"], ["Kolkata", " Delhi"]], then the output will be ["Chennai", " Mumbai", " Kolkata", " Delhi", "Bangalore"].To solve this, we will follow these steps −Define array ret and a map called graph.Define a method called visit. This will take airport name as ... Read More

159 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

170 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

229 Views
Suppose we have a balanced binary search tree, we have to create a function named is_valid_triplet() that returns true when there exist a triplet in given BST whose sum equals to 0, otherwise returns false. Design the method by following these constraints −expected time complexity is O(n^2)O(logn) extra space can be used.So, if the input is likethen the output will be True, as triplet is [-15, 7, 8]To solve this, we will follow these steps −Define a function bst_to_doubli_list(), this will take root, head, tail, if root is same as NULL, then −returnif left of root is not null, then ... Read More

163 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

134 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