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

1K+ Views
Suppose we have an array w of positive integers, were w[i] describes the weight of index i, we have to define a function pickIndex() which randomly picks an index in proportion to its weight.So if the input is like [1, 3], call pickIndex() five times, then the answer may come as − 0, 1, 1, 1, 0.To solve this, we will follow these steps −Define an array v, Through the initializer, initialize asn := w[0]for i in range 1 to size of ww[i] := w[i] + w[i – 1]n := w[i]v = wThe pickIndex() will work as follows −Take a ... Read More

1K+ Views
Suppose we have a binary array, we have to find the maximum length of a contiguous subarray with equal number of 0 and 1. So if the input is like [0, 1, 0], then the output will be 2 as [0, 1] or [1, 0] is the largest contiguous array with equal number of 0s and 1s.To solve this, we will follow these steps −ret := 0, n := size of nums, sum := 0make a map m, set m[0] := - 1for i in range 0 to size of nums – 1sum := sum + 1 when nums[i] is ... Read More

218 Views
Suppose we have a string and a string dictionary, we have to find the longest string in the dictionary that can be formed by deleting some of the characters of the given string. If there are more than one possible results, then just return the longest word with the smallest lexicographical order. If there is no result, then return a blank string. So if the input is like “abpcplea” and d = [“ale”, “apple”, “monkey”, “plea”], then the result will be “apple”.To solve this, we will follow these steps −Define a method called isSubsequence(). This will take s1 and s2j ... Read More

1K+ Views
Suppose we have a list of non-negative numbers and a target integer k, we have to write a function to check whether the array has a continuous subarray of size at least 2 that sums up to a multiple of k, sums up to n*k where n is also an integer. So if the input is like [23, 2, 4, 6, 7], and k = 6, then the result will be True, as [2, 4] is a continuous subarray of size 2 and sums up to 6.To solve this, we will follow these steps −Make a map m, set m[0] ... Read More

317 Views
Suppose we have a binary matrix with n_rows number of rows and n_cols number of columns. Here all values are initially 0. we have to define a function flip() which chooses a 0 value uniformly at random, changes it to 1, and then returns the position [row.id, col.id] of that value. Also, we have to write another function reset() which sets all values back to 0. We have to try to minimize the number of calls to system's Math.random() and optimize the time and space complexity.If we have the matrix of order 2x3, and we call flip four times, then ... Read More

815 Views
Suppose we have a string s, we have to find the longest palindromic subsequence's length in s. We can assume that the maximum length of s is 1000. So if the input is like “bbbab”, then output will be 4. One possible palindromic subsequence is “bbbb”.To solve this, we will follow these steps −x := s, then reverse x, n := size of sif n is 0, then return 0update s by adding one blank space before s, and update x by adding one blank space before xret := 0make one matrix dp of size (n + 1) x (n ... Read More

1K+ Views
Suppose we have a matrix of M x N elements, we have to find all elements of the matrix in diagonal order. So if the matrix is like −123456789The output will be [1, 2, 4, 7, 5, 3, 6, 8, 9]To solve this, we will follow these steps −Make an array ret, set row := 0 and col := 0, n := row count, m := col count, down := falsefor i in range 0 to n – 1x := i, y := 0create an array tempwhile x >= 0 and y < m, doinsert matrix[x, y] into temp, and ... Read More

328 Views
Suppose we have a list of non-overlapping axis-aligned rectangles rects, we have to write a function pick which randomly and uniformly picks an integer number, point in the space covered by the rectangles. So we have to keep in mind some points −An integer point is a point that has integer coordinates.A point on the perimeter of a rectangle is included in the space covered by the rectangles.The ith rectangle = rects[i] denotes [x1, y1, x2, y2], where [x1, y1] are the integer coordinates of the bottom-left corner, and [x2, y2] are the integer coordinates of the top-right corner.The length ... Read More

112 Views
Suppose in LOL world, there is a hero named Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, suppose we have given the Teemo's attacking ascending time series towards Ashe and the poisoning time duration per Teemo's attacking, we have to find the total time that Ashe is in poisoned condition. We can assume that Teemo attacks at the very beginning of a specific time point, and makes Ashe be in poisoned condition immediately.The input is like [1, 4] and 2, then the output will be 4. So this is because at time point 1, ... Read More

238 Views
Suppose we have an integer array, our task is to find all the different possible increasing subsequences of the given array, and the length of an increasing subsequence should be at least 2. So if the array is like [4, 6, 7, 7], then the output will be like − [[4, 6], [4, 7], [4, 6, 7], [4, 6, 7, 7], [6, 7], [6, 7, 7], [7, 7], [4, 7, 7]].To solve this, we will follow these steps −Define an array, called res to store all resultsMake a method called solve. This will take nums array, start and temp arrayif ... Read More