
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

103 Views
Suppose we have a 2D matrix, where the elements represent the height of a terrain. Let's imagine a situation where it will rain and all the spaces in the valleys get filled up.We have to find out the amount of rain that will be caught between the valleys.So, if the input is like666864586666then the output will be 3 as we can hold 3 units of water in between 4 and 5 squares.To solve this, we will follow these steps −Define a structure Data, that contains x and y coordinate and height hDefine a priority queue pq, it stores data items ... Read More

437 Views
Suppose we have a 2D matrix named 'edges', that represents an undirected graph. Every item in the matrix 'edges' represents an edge and is of the form (u, v, w). This means nodes u and v are connected and the edge has the weight w. We also have integers a and b, that represent an edge (a, b). We have to find out if the edge (a, b) is part of a minimum spanning tree.Note − the graph has to be connected and the edge (a, b) exists in the graph.So, if the input is like edges =[[0, 2, 100], ... Read More

408 Views
Suppose we have a list of unique and sorted numbers that represent breakpoints in a string. We want to create a tree out of these rules −There are nodes that have a value (a, b) where a and b are breakpoints. This means the node spans from indices [a, b] in the string.The root node spans over every breakpoint. (the whole string).The spans of a node's left and right child are ordered, contiguous, and contains the parent node's span.Leaf nodes' index of 'a' in breakpoints is 1 before the index of 'b' in breakpoints.The cost of a tree is determined ... Read More

280 Views
Suppose we have a 2D matrix and another value k. Our goal is to return a matrix that contains the lowest values of all k x k sub-matrices.So, if the input is like3568654312and k =2, then the output will be [[3, 5], [3, 3]] .From the input, we can see that the top left submatrix has the lowest value of 33 5 8 6The top right submatrix has the lowest value of 55 6 6 5The bottom left submatrix has the lowest value of 38 6 4 3The bottom right submatrix has the lowest value of 36 5 3 12To ... Read More

152 Views
Suppose we have a list of numbers called nums, The width of a sequence of numbers as the difference between the maximum and minimum number in the sequence. We have to find the sum of widths of all subsequences of nums. If the answer is very large then mod the result by 10^9+7.So, if the input is like nums = [7, 4, 9], then the output will be 15, as we have the subsequences like: [7], [4], [9], [7, 4], [7, 9], [4, 9], [7, 4, 9] and So the widths are 0, 0, 0, 3, 2, 5, 5, so ... Read More

223 Views
Suppose we have a list of numbers called nums and we can delete at most one element in the list. We have to find the maximum number of sublists that contain both the maximum and minimum values of the resulting list.So, if the input is like nums = [3, 2, 6, 2, 4, 10], then the output will be 8, as if we remove 10 we will get [3, 2, 6, 2, 4] and there are eight sublists where it contains both the max and the min −[2, 6][6, 2][2, 6, 2][3, 2, 6][6, 2, 4][2, 6, 2, 4][3, 2, ... Read More

153 Views
Suppose we have a list of numbers called nums and another value pos. We have to find a sublist A of nums that includes the index pos such that (minimum of A) * (size of A) is maximized then return the value.So, if the input is like nums = [-2, 2, 5, 4] pos = 3, then the output will be 8, as the best sublist is [5, 4], because (5, 4) = 4 and its size is 2 we have 4 * 2 = 8.To solve this, we will follow these steps −ans := A[pos], m := A[pos]i := ... Read More

368 Views
Suppose we have a string s, this is encoding a longer string. s is represented as the concatenation of n(t), n(t) represents the concatenation of t, n times, and t is either a regular string or it is another encoded string recursively. We have to find the decoded version of s.So, if the input is like s = "3(pi)2(3(am))0(f)1(u)", then the output will be "pipipiamamamamamamu"To solve this, we will follow these steps −i := 0Define a function parse() . This will takeans := a new listwhile i < size of s and s[i] is not same as ")", doif s[i] ... Read More

175 Views
Suppose we have a 2d matrix, we have to find the largest k × k submatrix where all of its elements are containing the same value, then find the value of k.So, if the input is like1183155525554555then the output will be 3, as there is a 3 × 3 square matrix of value 5.To solve this, we will follow these steps −n := row count of matrixm := column count of matrixDefine one 2D array dp of size (n x m) and fill with 1ret := 1for initialize i := n - 1, when i >= 0, update (decrease i ... Read More

147 Views
Suppose we have a lowercase string s, we have to split it into as few strings as possible such that each string is a palindrome and then find the number of strings.So, if the input is like s = "levelracecar", then the output will be 2, as there are two palindromes "level" and "racecar".To solve this, we will follow these steps −n := size of ADefine an array result of size (n + 1)result[n] := -1for initialize i := n - 1, when i >= 0, update (decrease i by 1), do −result[i] := n - i - 1for initialize ... Read More