
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++

203 Views
Suppose we have a list of words. These words are distinct. We have to devise an algorithm that will find all concatenated words in the give list of words. A concatenated word is actually a string that is comprised entirely of at least two shorter words in the given array.So if the words are like ["cow", "cows", "cowsgoatcows", "goat", "goatcowsgoat", "hippopotamuses", "deer", "deercowgoatcow"], then the output will be ["cowsgoatcows", "goatcowsgoat", "deercowgoatcow"]To solve this, we will follow these steps −Define a function isPresent(), this will take str, head, idx, an array dp, if idx >= size of str, then −return trueif ... Read More

204 Views
Suppose there are 1000 buckets, one of them is poisonous, others are filled with water. They all look similar. If a pig drinks the poison it will die within 15 minutes. What will be the minimum amount of pigs that we need to find out the poisonous bucket within one hour?So now consider for the general case and devise an algorithm for this. So, the general case is that If there are n different buckets and a pig drinking poison will die within m minutes, how many pigs are needed to find poisonous bucket within p minutes? There is exactly ... Read More

243 Views
Suppose we have an array A, where N numbers are present. A subsequence slice of that array is any sequence of integers like (K0, K1, K2, … Kn) such that 0 = 2. So we have to return the number of arithmetic slices.So if the input is like [2, 4, 6, 8, 10], then the answer will be 7, as there are 7 arithmetic slices. [2, 4, 6], [2, 4, 10], [4, 6, 8], [6, 8, 10], [2, 4, 6, 8], [4, 6, 8, 10], [2, 4, 6, 8, 10], To solve this, we will follow these steps −ret := ... Read More

783 Views
Suppose we have two values n and k. We have to find the lexicographically kth smallest integer in the range of 1 to n. So if the input is like n = 14 and k = 3, then the output will be 11, as the sequence will be [1, 10, 11, 12, 13, 14, 2, 3, 4, 5, 6, 7, 8, 9], then the kth number is 11.To solve this, we will follow these steps −Define a function findKthNumber(), this will take n, k,curr := 1(decrease k by 1)while k is non-zero, do −steps := call the function calcSteps(n, curr, curr + 1)if steps

393 Views
Suppose we have an array of positive integers and one value m. We can divide this array into m number of contiguous subarrays. We have to devise an algorithm to minimize the largest sum among these m subarrays.So if the array is say [7, 2, 4, 10, 9], and m = 2, then the sum will be 19, as we can make two subarrays like [7, 2, 4] and [10, 9], then the subarray with largest sum is 19.To solve this, we will follow these steps −Define a function splitArray(), this will take an array v, m, n := size ... Read More

2K+ Views
Suppose there is a frog that is crossing a river. The river is divided into x units and at each unit there may be a stone. The frog can jump on a stone, but not water. Here we have a list of stones' positions in sorted ascending order sequence, we have to check whether the frog is able to cross the river by landing on the last stone, or not. Initially, the frog is on the first stone and assume the first jump must be of 1 unit.When the frog's current jump was k units, then its next jump must ... Read More

148 Views
Suppose, we want to make a data structure, that supports some operations, these operations must be preformed in O(1) amount of time. So let these operations are like −insert(x): insert x into the collectionremove(x): delete x from the collectiongetRandom(): This will find random element form that collection.To solve this, we will follow these steps −Make an array numsmake one map mDefine a function insert(), this will take val, ret := when val is not in minsert size of nums at the end of m[val]insert { val, size of m[val] – 1} pair at the end of numsreturn retDefine a function ... Read More

136 Views
Suppose we have a 2D matrix, and an integer k. We have to find the max sum of a rectangle in the matrix, such that its sum is not greater than k. So, if the input is like −1010-32And k = 3, then the output will be 3, as the sum of marked rectangle is 3.To solve this, we will follow these steps −Define a function maxSumSubmatrix(), this will take one 2D array matrix and k, n := row number, m := column numberans := -inffor initialize l := 0, when l < m, update (increase l by 1), do ... Read More

524 Views
Suppose we have some envelops, these envelops has height and width values as pairs. We can put one envelop into another one if the height and width of second envelop both are smaller than the height and width of the first one. So, what will be the maximum number of envelops that we can put inside other. So, if the inputs are like [[5, 5], [6, 4], [6, 8], [2, 3]], then the output will be 3, as smallest envelop is [2, 3], then [5, 5], then [6, 8].To solve this, we will follow these steps −sort the array v ... Read More

612 Views
Suppose we have an integer array nums, we have to find the number of range sums that lie in range [lower, upper] both inclusive. The range sum S(i, j) is defined as the sum of the elements in nums from index i to index j where i ≤ j.So if the input is like [-3, 6, -1], lower = -2 and upper = 2, then the result will be 2, as the ranges are [0, 2], the sum is 2, [2, 2], sum is -2.To solve this, we will follow these steps −Define a function mergeIt(), this will take array ... Read More