
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

182 Views
Suppose we have a list of numbers called nums and another value k. We can split the list into k non-empty sublists. We have to find the minimum largest sum of the k sublists.So, if the input is like nums = [2, 4, 3, 5, 12] k = 2, then the output will be 14, as we can split the list like: [2, 4, 3, 5] and [12].To solve this, we will follow these steps −Define a function ok(), this will take array v, k, x,cnt := 0, sum := 0for each element i in v −if sum + i > x, then −sum := i(increase cnt by 1)Otherwisesum := sum + ireturn true when cnt

245 Views
Suppose we have a list of numbers called heights that represents the height of plants and we have another list of values called costs that represents the price needed to increase height of a plant by one. We have to find the smallest cost to make each height in the heights list different from adjacent heights.So, if the input is like heights = [3, 2, 2] costs = [2, 5, 3], then the output will be 3, as we can increase the last height by 1, which costs 3.To solve this, we will follow these steps −Define a function dp() ... Read More

163 Views
Suppose we have a binary matrix. Here 0 signifies an empty cell, and a 1 signifies a cell with a person. The distance between two cells is the maximum value between the difference in x coordinates and the difference in y coordinates. Now matrix is considered safe with a factor k if there is an empty square such that the distance from the cell to each person in the matrix, and each side of the matrix is all greater or equal to k. We have to find the maximum value of factor k for which we can be safe.So, if ... Read More

205 Views
Suppose we have a list of numbers called nums, and an another input called target, we have to find the size of the shortest sublist such that its sum value is same as target or larger. If there is no such sublist then return -1.So, if the input is like nums = [2, 11, -4, 17, 4] target = 19, then the output will be 2, as we can select [17, 4] to get sum of at least 19.To solve this, we will follow these steps −ps := a list with only one element 0for each num in nums, doinsert ... Read More

172 Views
Suppose we have a list of lists, we have to find the smallest difference that can be formed by picking one value from each of the lists and taking the difference between the maximum and the minimum number of the picked element.So, if the input is like lists = [ [30, 50, 90], [85], [35, 70]], then the output will be 20, as we can take 90, 85, 70 and 90 - 70 = 20To solve this, we will follow these steps −maxVal := -infret := infdefine a priority queue pqn := size of listsfor initialize i := 0, when ... Read More

298 Views
Suppose we have a list of numbers called nums, we have to check whether there are triplets (i, j, k) such that i < j < k and nums[i] < nums[k] < nums[j].So, if the input is like nums = [2, 12, 1, 4, 4], then the output will be True, as [2, 12, 4] matches the criteria because 2 < 4 < 12.To solve this, we will follow these steps −n := size of numsDefine an array left of size nleft[0] := nums[0]for initialize i := 1, when i < n, update (increase i by 1), do −left[i] := ... Read More

734 Views
Suppose we have a binary matrix where 1 represents land and 0 represents water. And an island is a group of 1's that are surrounded by 0s (water) or by the edges. We have to find all of the islands that are completely surrounded by water and modify them into 0s. As we know an island is completed surrounded by water if all of the neighbors (horizontal and vertical not diagonal) are 0s (none of the neighbors are edges).So, if the input is like10000110011001100001then the output will be10000000000000000001To solve this, we will follow these steps −row := row count of ... Read More

174 Views
Suppose we have two strings s and t. We have to find the length of the shortest string that has both s and t as subsequences.So, if the input is like s = "pipe" t = "people", then the output will be 7, as one possible supersequence is "pieople".To solve this, we will follow these steps −m := size of s, n := size of ttable := a table of size (n + 1) x (m + 1) and fill with 0for i in range 0 to m, dofor j in range 0 to n, doif i is same as ... Read More

453 Views
Suppose we have a binary matrix, where 0 represents water and 1 represents the land. An island is a group of connecting 1s in 4 directions. Islands are either surrounded by 0s (water) or by the edges. We have to find the length of shortest bridge that connects two islands.So, if the input is like001101100then the output will be 1. This will connect (1, 0) to (1, 2) points.To solve this, we will follow these steps −row := row count of matrixcol := column count of matrixDefine a function dfs() . This will take i, j, sif (i, j) is ... Read More

269 Views
In this problem, we are given an N vertex tree and Q queries each consisting of two values i and j. Our task is to create a program to solve a Query for ancestor-descendant relationship in a tree.To solve each query, we need to check whether the node i is the ancestor of node j in the tree.Let’s take an example to understand the problem, InputQ = 2, query[][] = {{3, 5}, {1, 6}}OutputNo YesExplanationi = 3, j = 5: The node 3 is not the ancestor of node 5. Return NO. i = 1, j = 6: The node ... Read More