
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 26504 Articles for Server Side Programming

330 Views
Suppose we have an array of integers, we have to check whether there are two distinct indices i and j in the array such that the absolute difference between nums[i] and nums[j] is at most t. And the absolute difference between i and j is at most k. So if input is like [1, 2, 3, 1], then if k = 3 and t = 0, then return true.To solve this, we will follow these steps −Make a set s, n := size of nums arrayfor i in range 0 to n – 1x is index of set element starting ... Read More

1K+ Views
Suppose we have a DNA sequence. As we know, all DNA is composed of a series of nucleotides abbreviated such as A, C, G, and T, for example: "ACGAATTCCG". When we are studying DNA, it is sometimes useful to identify repeated sequences within the DNA.We have to write one method to find all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule.So if the input is like “AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT”, then the output will be ["AAAAACCCCC", "CCCCCAAAAA"].To solve this, we will follow these steps −Define an array ret, n := size of s, create two sets called visited ... Read More

3K+ Views
Suppose we have to compare two version numbers version1 and version2. If the version1 > version2 then return 1; otherwise when version1 < version2 return -1; otherwise return 0. We can assume that the version strings are non-empty and contain only digits and the dot (.) characters. The dot character does not represent a decimal point and is used to separate number sequences. So for example, 2.5 is not "two and a half" or "halfway to version three", it is the fifth second-level revision of the second first-level revision.We can assume the default revision number for each level of a ... Read More

3K+ Views
Suppose we have an integer n. We have to return 1 to n in lexicographic order. So for example when 13 is given, then the output will be [1, 10, 11, 12, 13, 2, 3, 4, 5, 6, 7, 8, 9].To solve this, we will follow these steps −define one array ret of size ncurr := 1for i in range 0 to n – 1ret[i] := currif curr * 10 = n, then curr := curr / 10increase curr by 1while curr is divisible by 10, then curr := curr / 10return retExample(C++)Let us see the following implementation to get better understanding − Live Demo#include using namespace std; void print_vector(vector v){ cout

408 Views
Suppose we have a 2D matrix called matrix, we have to find the sum of the elements inside the rectangle defined by its upper left corner using (row1, col1) and lower right corner using (row2, col2).So if the matrix is like −3014256321120154101710305The above rectangle with the blue color defined by (2, 1) and (4, 3), this contains sum 8.So if we perform some query like sumRegion(2, 1, 4, 3), sumRegion(1, 1, 2, 2), sumRegion(1, 2, 2, 4), these will return 8, 11, 12 respectively.To solve this, we will follow these steps −Define a matrix called dp.Initialize the task as followsn ... Read More

278 Views
Suppose we have a list of folders, we have to remove all sub-folders in those folders and return in any order the folders after removing. Here if a folder[i] is located within another folder[j], it is denoted as subfolder of it. The paths will be like folder1/subfolder2/… etc.Suppose the input is like["/myfolder", "/myfolder/secondfolder", "/another/document", "/another/document/extrafolder", "/another/final"], then the output will be: ["/myfolder", "/another/final", "/another/document"]To solve this, we will follow these steps −sort the folder array based on the length of the pathscreate one map m, and another array ansfor i in range 0 to size of path array – 1s ... Read More

669 Views
Suppose we have some coins. The i-th coin has a probability prob[i] of facing heads when tossed. We have to show the probability that the number of coins facing heads equals target if you toss every coin exactly once. So if the prob array is like [0.5, 0.5, 0.5, 0.5, 0.5] and target is 0, then the output will be 0.03125.To solve this, we will follow these steps −n := size of prob arraycreate one 2d array of size n x (target + 5)set dp[0, 0] = 1 – prob[0] and dp[0, 1] := prob[0]for i in range 1 to ... Read More

1K+ Views
Suppose we have the availability time slots lists slots1 and slots2 of two people and a meeting duration d, we have to find the earliest time slot that works for both of them and is of duration d. If there is no common time slot that satisfies the requirements, then show an empty array. Here the format of a time slot is an array of two elements [start, end] representing an inclusive time range from start to end. we can assume that no two availability slots of the same person intersect with each other. That is, for any two time ... Read More

675 Views
Suppose a die simulator generates a random number from 1 to 6 for each roll. We want to introduced a constraint to the generator such that it cannot roll the number i more than rollMax[i] (1-indexed) consecutive times. Consider we have an array of integers rollMax and an integer n, we have to return the number of distinct sequences that can be obtained with exact n rolls. The two sequences are considered different if at least one element differs from each other. So if n is 2, then rollMax = [1, 1, 2, 2, 2, 3], then the output will ... Read More