
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 33676 Articles for Programming

432 Views
Suppose we have a rooted general tree with n nodes, whose nodes are numbered from 0 to n-1. Each node has a label with lowercase English letter. The labels are given as input in labels array, where lables[i] contains label for ith node. The tree is represented by edge list where each edge e has [u, v] represents u is parent and v is child. We have to find an array A of size n, represents number of nodes in the subtree of the ith node with same label as iSo, if the input is likeHere n = 5 and ... Read More

526 Views
Suppose we have an undirected weighted graph with n nodes (nodes are numbered from 0 onwards), This graph is given as input using edge list, for each edge e, it has a probability of success of traversing that edge probability[e]. We also have start and end nodes, we have to find the path with the maximum probability of success to go from start to end and return its success probability. If we cannot find any path, then return 0.So, if the input is likethen the output will be 0.24 because there are two paths from node 0 to 2, one ... Read More

192 Views
Suppose we have a binary string s. We have to find the number of substrings with all characters 1's. The answer may be very large so return result mod 10^9 + 7.So, if the input is like s = "1011010", then the output will be 5 because 1. four times "1" 2. one time "11"To solve this, we will follow these steps −m := 10^9+7result := 0div := divide the binary string by splitting it using '0'for each x in div, doif x is empty, then go for next iterationresult := result + quotient of (size of x *(size of ... Read More

648 Views
Suppose we have an array called nums. We can change one element from this array to any value in one move. We have to find the minimum difference between the largest and smallest value of nums after preforming at most 3 moves.So, if the input is like nums = [3,7,2,12,16], then the output will be 1 because we can make given array to [1,1,0,1,1], so the maximum is 1 and minimum is 0, so the difference is 1.To solve this, we will follow these steps −if size of nums

410 Views
Suppose we have an array nums with n positive elements. If we compute the sum of all non-empty contiguous subarrays of nums and then sort them in non-decreasing fashion, by creating a new array of n*(n+1)/2 numbers. We have to find the sum of the numbers from index left to index right (1-indexed), inclusive, in the new array. The answer may be very large so return result modulo 10^9 + 7.So, if the input is like nums = [1, 5, 2, 6] left = 1 right = 5, then the output will be 20 because here all subarray sums are ... Read More

648 Views
Suppose we have m x n binary matrix, we have to find how many submatrices have all ones.So, if the input is like101011011then the output will be 13 as there are 6 (1x1) matrices, 3 (2, 1) matrices, 2 (1x2) matrices, 1 (3x1) matrix and 1 (4x4) matrix.To solve this, we will follow these steps −m := row count of matrixn := column count of matrixdp := a zero matrix of same size m x nfor i in range 0 to m - 1, dofor j in range 0 to n - 1, doif i is same as 0 and ... Read More

201 Views
Suppose we have m x n binary matrix, we have to find how many square submatrices have all ones.So, if the input is like.011111110111then the output will be 15, as there are 10 squares of side 1. 4 squares of side 2 and 1 square of side 3. Then total number of squares = 10 + 4 + 1 = 15.To solve this, we will follow these steps −if matrix has single one, thenreturn 1rows := row count of matrixcols := column count of matrix[0]result := 0for row in range 0 to rows - 1, dofor col in range 0 ... Read More

619 Views
Suppose we have an array called nums and another value k. We have to find the number of non-empty subsequences of nums such that the sum of the minimum and maximum element on it is smaller or equal to k. The answers may be very large so return answer mod 10^9 + 7.So, if the input is like nums = [4,6,7,8] k = 11, then the output will be 4 because there are subsequences like[4], here minimum is 4, maximum is 4, so 4+4

318 Views
Suppose we have an array called nums, this array contains even number of elements, and have another value k. We have to split nums into exactly n/2 pairs such that the sum of each pair is divisible by k. If we can do so then return true, otherwise false.So, if the input is like nums = [9, 5, 3, 4, 7, 10, 20, 8] k = 3, then the output will be True because we can make pairs like (9, 3), (5, 7), (4, 20), (8, 10), sum of all pairs are divisible by 3.To solve this, we will follow ... Read More

423 Views
Suppose we have a binary array called nums, we can delete one element from it. We have to find the size of the longest non-empty subarray which is containing only 1's in the resulting array. If there is no such subarray, then return 0.So, if the input is like nums = [1, 0, 1, 1, 1, 0, 1, 1, 0], then the output will be 5 because by removing 0 from position 5, we can get a subarray [1, 1, 1, 1, 1] there are five 1s.To solve this, we will follow these steps −if 0 is not in nums, ... Read More