
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

310 Views
Suppose we have a string such as "word" and that contains the following abbreviations: ["word", "1ord", "w1rd", "wo1d", "wor1", "2rd", "w2d", "wo2", "1o1d", "1or1", "w1r1", "1o2", "2r1", "3d", "w3", "4"]. We also have a target string and a set of strings in a dictionary, we have to find an abbreviation of this target string with the smallest possible length such that it does not conflict with abbreviations of the strings in the dictionary. Here each number or letter in the abbreviation is considered as length = 1. So as an example, the abbreviation "a32bc" is of length = 4.So, if ... Read More

256 Views
Suppose we have N axis-aligned rectangles, we have to check whether they all together form an exact cover of a rectangular region or not. Here each rectangle is represented as a bottom-left point and a top-right point. So a unit square is represented as [1, 1, 2, 2]. (bottom-left point is (1, 1) and top-right point is (2, 2)).So, if the input is like rectangles = [[1, 1, 3, 3], [3, 1, 4, 2], [3, 2, 4, 4], [1, 3, 2, 4], [2, 3, 3, 4]], then the output will be true as all 5 rectangles together form an exact ... Read More

585 Views
Suppose we have a non-empty string s and an integer k; we have to rearrange the string such that the same characters are at least distance k from each other. Given strings are in lowercase letters. If there is no way to rearrange the strings, then we will an empty string.So, if the input is like s = "aabbcc", k = 3, then the output will be "abcabc" this is because same letters are at least distance 3 from each other.To solve this, we will follow these steps −ret := an empty stringDefine one map mn := size of sfor ... Read More

1K+ Views
Suppose we have a string; we have to calculate the length of the longest substring T that contains at most k distinct characters.So, if the input is like s = "eceba", k = 2, then the output will be 3 as T is "ece" which its length is 3.To solve this, we will follow these steps −ans := 0Define one map mn := size of sx := 0for initialize j := 0, i := 0, when j < n, update (increase j by 1), do −(increase m[s[j]] by 1)if m[s[j]] is same as 1, then −(increase x by 1)while (x > k and i k && i

573 Views
Suppose we have one matrix; we have to find the length of the longest increasing path. From each cell, we can either move to four directions − left, right, up or down. We cannot move diagonally or move outside of the boundary.So, if the input is like994668211then the output will be 4 as the longest increasing path is [3, 4, 5, 6].To solve this, we will follow these steps −Define a function solve(). This will take i, j, matrixif dp[i, j] is non-zero, thenreturn dp[i, j]dp[i, j] := 1temp := 0for r in range i-1 to i+2, dofor c in ... Read More

685 Views
Suppose we want to make a house on an empty land which reaches all buildings in the shortest amount of distance. We can only move four directions like up, down, left and right. We have a 2D grid of values 0, 1 or 2, where −0 represents an empty land which we can pass by freely.1 represents a building which we cannot pass through.2 represents an obstacle which we cannot pass through.So, if the input is like102010000000100then the output will be 7 as Given three buildings are present at (0, 0), (0, 4), (2, 2), and an obstacle is at ... Read More

487 Views
Suppose we have a 2D matrix called matrix, we have to calculate the sum of the elements inside the rectangle defined by its upper left corner and lower right corner.So, if the input is like3014256321120154101710305So will be methods to find sum, update value, if we call them likesumRegion(2, 1, 4, 3)update(3, 2, 2)sumRegion(2, 1, 4, 3) ,then the output will be 8 and 10, as the above rectangle (with the green color) is defined by (2, 1) and (4, 3), which contains sum = 8.To solve this, we will follow these steps −Define one 2D array treeDefine one 2D array ... Read More

416 Views
Suppose we have an image and that image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. Here the black pixels are connected, so there is only one black region. Pixels are connected horizontally and vertically. If we have a location (x, y) of one of the black pixels, we have to find the area of the smallest (axis-aligned) rectangle that encloses all black pixels.So, if the input is like001001100100and x = 0, y = 2, then the output will be 6To solve this, we will follow these steps −Define one ... Read More

919 Views
Suppose we have one binary tree and we have to serialize and deserialize them. As we know that the serialization is the process of converting a data structure or object into a sequence of bits so we can store them in a file or memory buffer, and that can be reconstructed later in the same or another computer environment.Here we have to devise an algorithm to serialize and deserialize binary tree. The binary tree is a rooted tree in which each node has no more than 2 children.So, if the input is likethen the output will be Serialize − 1 ... Read More

262 Views
Suppose there is a group of two or more people and they wants to meet and minimize the total travel distance. We have a 2D grid of values 0 or 1, where each 1 mark the home of someone in the group. The distance is calculated using the formula of Manhattan Distance, so distance(p1, p2) = |p2.x - p1.x| + |p2.y - p1.y|.So, if the input is like100010000000100then the output will be 6 as from the matrix we can understand that three people living at (0, 0), (0, 4), and (2, 2): The point (0, 2) is an ideal meeting ... Read More