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
 
C++ Articles - Page 363 of 719
 
			
			245 Views
Suppose we have a blacklist called B. This is holing unique integers from range [0, N), we have to define a function to return a uniform random integer from range [0, N) which is NOT in B. We will try to make this function more optimized by reducing random(). function call. Suppose the input array is likeTo solve this, we will follow these steps −Define one mapWe will initialize with N and array v.for initalize i := 0, when i < size of v, update (increase i by 1), do −if v[i] < N, then:, m[v[i]] := -1M := N ... Read More
 
			
			429 Views
Suppose we have N different types of stickers. In each type of sticker has a lowercase English word on it. We would like to spell out the given target string by cutting individual letters from our collection of stickers and rearranging them. We can use each sticker more than once if needed, and we have infinite quantities of each sticker.We have to find the minimum number of stickers that we need to spell out the target? If the task is impossible, return -1.So if the input is like [“dog”, “sentence”, ”antenna”], and target is “dance”, then the answer will be ... Read More
 
			
			211 Views
Suppose we have one array called nums of positive integers, we have to find three non-overlapping subarrays with maximum sum. Here each subarray will be of size k, and we want to maximize the sum of all 3*k entries.We have to find the result as a list of indices representing the starting position of each interval. If there are multiple answers, we will return the lexicographically smallest one.So if the input is like [1, 2, 1, 2, 6, 8, 4, 1] and k = 2, then the result will be [0, 3, 5], so subarrays are [1, 2], [2, 6], ... Read More
 
			
			271 Views
Suppose we have a rooted tree. This is a directed graph such that, there is exactly one node (which is the root) for which all other nodes are descendants of this node, and every node has exactly one parent, except for the root node. Root has no parents.In the given input a directed graph that started as a rooted tree with N nodes (All values are unique), with one additional directed edge added. The added edge has two different vertices chosen from 1 to N, and was not an edge that already existed.Graph will be a 2D-array of edges. Each ... Read More
 
			
			377 Views
Suppose we know about one Multiplication Table. But could we find out the k-th smallest number quickly from the multiplication table? So if we have to height m and the length n of a m * n Multiplication Table, and one positive integer k, we have need to find the k-th smallest number in this table.So if m = 3 and n = 3 and k is 6, then the output will be 4., this is because the multiplication table is like −1231123224633696th smallest element is 4 as [1, 2, 2, 3, 3, 4, 6, 6, 9]To solve this, we ... Read More
 
			
			286 Views
Suppose there is a strange printer It has some requirements −The printer can print only a sequence of the same character each time.In each turn, the printer can print new characters starting from and ending at any places, and will cover the original existing characters.So if we have a string consists of lower letters, our task is to count the minimum number of turns the printer needed in order to print it.So if the input is like “aaabba”, then it will take 2 turns, first prints aaaaa then b’s by replacing the characters.To solve this, we will follow these steps ... Read More
 
			
			290 Views
Suppose there is a message, that is containing letters from A-Z is being encoded to numbers using the following mapping way −'A' -> 1, 'B' -> 2, ... , 'Z' -> 26Now, the encoded string can also contain the character '*', which can be treated as one of the numbers from 1 to 9. So if we have the encoded message containing digits and the character '*', then we have to find the total number of ways to decode it. If the answer is very long, we can use mod 109 + 7 to get the final result. So if ... Read More
 
			
			300 Views
Suppose we have k lists of sorted integers. We have to search the smallest range that includes at least one number from each of the k lists. Here the range [a, b] is smaller than range [c, d] when b-a < d-c or a < c if b-a == d-c.So if the input is like [[4, 10, 15, 25, 26], [0, 9, 14, 20], [5, 18, 24, 30]], then the output will be [14, 18]To solve this, we will follow these steps −minRange := inf, maxRange := -inf, rangeSize := inf, tempMinRange := inf, tempMaxRange := -infn := size of ... Read More
 
			
			300 Views
Suppose we have two integers n and k, we have to find how many different arrays consist of numbers from 1 to n such that there are exactly k inverse pairs. The inverse pair is for ith and jth element in the array, if i < j and a[i] > a[j] it is called an inverse pair. Here the answer may be very large, the answer should be modulo $10^{9}$ + 7.So if the input is like n = 3 and k = 1, then the output will be 2 as the arrays [1, 3, 2] and [2, 1, 3] ... Read More
 
			
			372 Views
Suppose we have a positive integer n. We have to find the non-negative integers less than or equal to n. The constraint is that the binary representation will not contain consecutive ones. So if the input is 7, then the answer will be 5, as binary representation of 5 is 101.To solve this, we will follow these steps −Define a function convert(), this will take n, ret := empty stringwhile n is non-zero, do −ret := ret + (n mod 2)n := right shift n, 1 timereturn retFrom the main method, do the following −bits := call the function convert(num)n ... Read More