
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

510 Views
Suppose we have two words S and T, we have to find the minimum number of operations needed to convert from S to T. The operations can be of three types, these areinsert a character, delete a characterreplace a character.So if the input strings are “evaluate” and “fluctuate”, then the result will be 5.To solve this, we will follow these steps −n := size of s, m := size of t, create an array dp of size n + 1for i in range 0 to ndp[i] := new array of size m + 1for j in range 0 to m:dp[i, ... Read More

282 Views
Suppose we have a string s, we have to find the number of distinct palindromes we can generate using all characters. If the answer is very large then mod the result by 10^9 + 7.So, if the input is like s = "xyzzy", then the output will be 2, as we can make "zyxyz" and "yzxzy"To solve this, we will follow these steps −m = 10^9+7char_freq := a map holding each character of s and their frequenciesodd := 0for each character k and frequency v in char_freq, doif v mod 2 is 1, thenodd := odd + 1if odd > ... Read More

349 Views
Suppose we have a graph as an adjacency list representation, we have to find 2D matrix M whereM[i, j] = 1 when there is a path between vertices i and j.M[i, j] = 0 otherwise.So, if the input is likethen the output will be1111101111011110111101111To solve this, we will follow these steps −ans:= a 2d matrix of size n x n, where n is the number of vertices, fill with 0sfor i in range 0 to n, doq:= a queue, and insert i at firstwhile q is not empty, donode:= first element of q, and delete first element from qif ans[i, ... Read More

254 Views
Suppose we have a number n, number of faces, and a total value, we have to find the number of ways it is possible to throw n dice with faces each to get total. If the answer is very large mod the result by 10**9 + 7.So, if the input is like n = 2 faces = 6 total = 8, then the output will be 5, as there are 5 ways to make 8 with 2 6-faced dice: (2 and 6), (6 and 2), (3 and 5), (5 and 3), (4 and 4).To solve this, we will follow these ... Read More

178 Views
Suppose we have a binary tree, we have to find the sum of each of the diagonals in the tree starting from the top to bottom right.So, if the input is likethen the output will be [27, 18, 3] as the diagonals are [12, 15], [8, 10], [3]. So the sum values are [27, 18, 3]To solve this, we will follow these steps −Define a function traverse() . This will take node, numLeft, outputif node is null, thenreturnif numLeft >= size of output , theninsert data of node at the end of outputotherwise, output[numLeft] := output[numLeft] + data of nodeif ... Read More

523 Views
Suppose we have n x m matrix Mat, we have to sort this Mat diagonally in increasing order from top-left to the bottom right, so that all elements in the diagonals are sorted. So if the input matrix is like −331122121112The output matrix will be −111112221233To solve this, we will follow these steps −Define a method called solve(), this will take si, sj and matrix matn := number of rows and m := number of columnsmake an array called tempi:= si and j := sj, and index := 0while i < n and j < m, doinsert m[i, j] into ... Read More

178 Views
Suppose two friends Amal and Bimal are playing a game with a sorted list of numbers called nums. In this game in a single turn, Amal chooses any three numbers. Bimal removes one of them, and then Amal removes one of them. The list starts out with an odd number of elements. Here Amla wishes to minimize the number of turns required to make the list contain no repeated elements, Bimal wishes to maximize the number of turns. If Amal and Bimal act optimally, we have to find how many turns are needed for this game.So, if the input is ... Read More

133 Views
Suppose we have two strings S and T and they are permutations of each other. Suppose there is an operation where we remove either the first or the last character in S and insert it anywhere in the string. Then find the minimum number of operations needed to convert S into T.So, if the input is like s = "zyvxw" t = "vwxyz", then the output will be 3, as these operations are: Remove "w" and insert it after "v" to get "zyvwx" Remove "z" and insert it after "x" to get "yvwxz" Remove "y" and insert it after "x" ... Read More

392 Views
Suppose we have we have a binary tree, we will repeatedly delete all leaves that have even values. After deleting all, if it has only root with even values, that will be deleted also.So, if the input is likethen the output will beTo solve this, we will follow these steps −Define a function solve() . This will take rootif root is null, thenreturn nullleft of root := solve(left of root)right of root := solve(right of root)if root is leaf and data of root is even, thenreturn nullreturn rootLet us see the following implementation to get better understanding −Exampleclass TreeNode: ... Read More

352 Views
Suppose we have mapping like 'a' = 1, 'b' = 2, ... 'z' = 26, and we have an encoded message message string, we have to count the number of ways it can be decoded.So, if the input is like message = "222", then the output will be 3, as This can be decoded 3 ways: bbb, bv, and vb.To solve this, we will follow these steps −memo := a list of 0s of size same as message size + 1memo[0] := 1memo[1] := 1 when message[0] is not same as "0" otherwise 0for i in range 2 to size ... Read More