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
Programming Articles - Page 1179 of 3363
427 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
672 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
223 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
654 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
343 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
448 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
661 Views
Suppose we have two positive values n and k. Now consider we have a list of all factors of n sorted in ascending order, we have to find the kth factor in this list. If there are less than k factors, then return -1.So, if the input is like n = 28 k = 4, then the output will be 7 because, the factors of 28 are [1, 2, 4, 7, 14, 28], fourth one is 7.To solve this, we will follow these steps −if k is same as 1, thenreturn 1cand := a list with one element [1]for i ... Read More
1K+ Views
Suppose we have an array of n strings called names. We have to make n directories in the file system such that, at the ith minute, we will create a directory with the name names[i]. Two files cannot have the same name, if we enter a duplicate directory name the system will have a suffix addition to its name in the form of (k), here, k is the smallest positive integer such that the obtained name remains unique. We have to find an array of strings of length n where ans[i] is the actual name that will be assign to ... Read More
726 Views
Suppose we have an array with integers called nums, we also have another two values m and k. Now, we need to make m bouquets. To make one bouquet we need k adjacent flowers from the garden. Here the garden consists of n different flowers, the ith flower will bloom in the bloomDay[i]. Each flower can be used inside only one bouquets. We have to find the minimum number of days need to wait to make m bouquets from the garden. If we cannot make m bouquets, then return -1.So, if the input is like bloomDay = [5, 5, 5, ... Read More
832 Views
Suppose we have an array called nums where only integers are stored. If we have a number k. We have to find least number of unique elements after removing exactly k elements.So, if the input is like nums = [5, 4, 2, 2, 4, 4, 3], k = 3, then the output will be 2, because if we remove 5 and 3, and either any one of 2s or any one of 4s, then there only 2 and 4 will be left.To solve this, we will follow these steps −dictionary:= a new mapfor each num in nums, doif num is ... Read More