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
-
Economics & Finance
Articles by Arnab Chakraborty
Page 131 of 377
Find 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 MoreBaseball Game in Python
Suppose we have a baseball game point recorder. We have a list of strings; each string can be one of the 4 following types −Integer (one round's score) − Indicates the number of points we get in this round."+" (one round's score) − Indicates the points we get in this round are the sum of the last two valid round's points."D" (one round's score ) − Indicates the points we get in this round are the doubled data of the last valid round's points."C" (an operation, which isn't a round's score) − Indicates the last valid round's points we get ...
Read MoreEmployee Importance in Python
Suppose we have a data structure of employee information, there are employee's unique id, his importance value and his direct subordinates' id. As an example, employee 1 is the leader of employee 2, and employee 2 is the leader of employee 3. And suppose their importance values are 15, 10 and 5, respectively. Then employee 1 has a data structure like [1, 15, [2]], and employee 2 has [2, 10, [3]], and employee 3 has [3, 5, []].So, if we have the employee information of a company, and an employee id, we have to find the total importance value of ...
Read MoreStrobogrammatic Number III in C++
Suppose we want to define a function to count the total strobogrammatic numbers that exist in the range of (low and high). As we know that a strobogrammatic number is a number that looks the same when rotated 180 degrees.So, if the input is like low = "50", high = "100", then the output will be 3 as there are three results, 69, 88, and 96.To solve this, we will follow these steps −Define a function findStrobogrammatic(), this will take n, Define an array retif n & 1 is non-zero, then −insert "0" at the end of retinsert "1" at ...
Read MoreBinary Number with Alternating Bits in C++
Suppose we have a positive integer, we have to check whether it has alternating bits − so, two adjacent bits will always have different values.So, if the input is like 10, then the output will be True, as binary representation of 10 is 1010.To solve this, we will follow these steps −p := n AND 1if n < 2, then −return truen := n/2while n is non-zero, do −c := n AND 1if c XOR p is same as 0, then −return falsep := cn := n/2return trueLet us see the following implementation to get better understanding −Example#include using ...
Read More