
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 10476 Articles for Python

165 Views
Suppose we have two lists of numbers nums0 and nums1 of the same length and two other values d as distance and c as cost. If we start from index 0 at either nums0 or nums1 and want to end up at the final index of either list. Now, in each round, we can select to switch to the other list for cost of cost. Then we can jump forward at most d distance away where the c cost of landing at an index is the value at that point. So we have to find the minimum total cost possible ... Read More

166 Views
Suppose we have a binary string, and we can swap any two bits. We have to find the minimum number of swaps required to group all 1s together.So, if the input is like s = "0111001", then the output will be 1, as We can perform these swaps: 0111001 -> 1111000.To solve this, we will follow these steps −data := a list of 0s and 1s from the given binary stringset one := 0, n:= length of data arraymake an array summ of size n, and fill this with 0, set summ[0] := data[0]one := one + data[0]for i in ... Read More

363 Views
Suppose we have a list of sorted numbers called stones and this is representing the positions of stones on a river that we are trying to cross. To cross the river, we must finish at the last stone. Now in each step, we can jump (k - 1, k, or k + 1) steps ahead where k is the distance of the last jump. We have to check whether we can cross the river or not.So, if the input is like stones = [0, 1, 3, 4, 5, 6, 8, 9, 13], then the output will be True, as we ... Read More

200 Views
Suppose we have a list of colors (R, G, B). Now if two different colors are there next to each other then they can transform into a single color item of the third color. We have to find the smallest number of them remaining after any possible sequence of such transformations.So, if the input is like colors = ["G", "R", "G", "B", "R"], then the output will be 1 as it can transform like below −To solve this, we will follow these steps −n := size of colorsif colors has only one distinct color, thenreturn nif n

192 Views
Suppose we have a binary matrix where, 0 represents water and 1 represents land. Now we have to find the land which has the longest Manhattan distance from water and finally return the distance.So, if the input is like1111110111110011then the output will be 3, as [0, 0] cell has Manhattan distance of 3 from water.To solve this, we will follow these steps −if A is empty, thenreturn 0R := row count of matrix, C := column count of matrixdistance := a matrix of order R x C and fill with 0q := a double ended queue with some pairs (r, ... Read More

254 Views
Suppose we have a number n, we have to find the number of ways we can fill a (3 x n) block with 1 x 2 dominos. We can rotate the dominos when required. If the answer is very large then return this mod 10^9 + 7.So, if the input is like n = 4, then the output will be 11.To solve this, we will follow these steps −m = 10^9 + 7if n is odd, thenreturn 0cs := 1, os := 0for i in range 2 to n, increase by 2, docs := 3 * cs + osos := ... Read More

379 Views
Suppose we have four numbers n, a, b, and c. We have to find the nth (0 indexed) term of the sorted sequence of numbers divisible by a, b or c.So, if the input is like n = 8 a = 3 b = 7 c = 9, then the output will be 18, as The first 9 terms of the sequence are [1, 3, 6, 7, 9, 12, 14, 15, 18].To solve this, we will follow these steps −if minimum of a, b, c is same as 1, thenreturn nab := lcm(a, b), bc := lcm(b, c), ca := ... Read More

357 Views
Suppose we have a list of unique numbers called nums, so we have to find the largest subset such that every pair of elements in the subset like (i, j) satisfies either i % j = 0 or j % i = 0. So we have to find the size of this subset.So, if the input is like nums = [3, 6, 12, 24, 26, 39], then the output will be 4, as the largest valid subset is [3, 6, 12, 24].To solve this, we will follow these steps −dp := a list of size nums and fill with 1sort the list numsn := size of numsif n

119 Views
Suppose we have a list of words and another value k. We have to find the number of sublists in the given words such that there are exactly k different words.So, if the input is like words = ["Kolkata", "Delhi", "Delhi", "Kolkata"] k = 2, then the output will be 5, as the following sublists have 2 unique words: ["Kolkata", "Delhi"], ["Delhi", "Kolkata"], ["Kolkata", "Delhi", "Delhi"], ["Delhi", "Delhi", "Kolkata"], ["Kolkata", "Delhi", "Delhi", "Kolkata"], but not ["Delhi", "Delhi"] as there is only one unique word.To solve this, we will follow these steps −Define a function work() . This will take words, ... Read More

180 Views
Suppose we have a number and a list of edges. These n different nodes labeled as 0 to N. These nodes are forming a network. Each edge is in the form (a, b, t) of an undirected graph, this is representing if we try to send message from a to b or b to a, it will take t time. When a node receives a message, it immediately floods the message on to a neighboring node. If all nodes are connected, we have to find how long it will take for every node to receive a message that starts at ... Read More