Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles by Arnab Chakraborty
Page 115 of 377
Find if neat arrangement of cups and shelves can be made in C++
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 MoreFind if there is a path of more than k length from a source in C++
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 MoreFind if there is a triplet in a Balanced BST that adds to zero in C++
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 MoreFind Itinerary from a given list of tickets in C++
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 MoreFind Jobs involved in Weighted Job Scheduling in C++
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
Read MoreFind k-th smallest element in BST (Order Statistics in BST) in C++
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 MoreFind longest bitonic sequence such that increasing and decreasing parts are from two different arrays in C++
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 MoreFind longest palindrome formed by removing or shuffling chars from string in C++
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 MoreFind lost element from a duplicated array in C++
ConceptWith respect of given two arrays which are duplicates of each other except one element, that means one element from one of the array is missing, our task to determine that missing element.Inputarr1[] = {2, 5, 6, 8, 10} arr2[] = {5, 6, 8, 10}Output22 is missing from second array.Inputarr1[] = {3, 4, 5, 6} arr2[] = {3, 4, 5, 6, 7}Output77 is missing from first array.MethodHere, we apply one simple solution where we iterate over arrays and verify element by element and mark the missing element when an unmatched is detected. But the drawback of this solution is that ...
Read MoreFind maximum difference between nearest left and right smaller elements in C++
ConceptWith respect of a given an array of integers, our task is to determine the maximum absolute difference between the nearest left and the right smaller element of every element in the array. It should be noted that if there is no smaller element on right side or left side of any element then we accept zero as the smaller element. Here, for example for the leftmost element, the nearest smaller element on the left side is set as 0. In the same way, for rightmost elements, the smaller element on the right side is set as 0.Inputarr[] = {3, ...
Read More