
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

3K+ Views
Suppose we have a binary tree representing a game state of a two player game. Every internal node is filled with 0 and the leaves values represent the end score. Player 1 wants to maximize the end score while player 2 wants to minimize the end score. Player 1 will always make moves on nodes at even levels and player 2 will always make moves on odd levels. We have to fill in the binary tree with the resulting scores assuming both of players play optimally.So, if the input is likethen the output will beTo solve this, we will follow ... Read More

313 Views
Suppose we have a list of numbers called nums and two values x and y, we have to find the maximum sum of two non-overlapping sublists in nums which have lengths x and y.So, if the input is like nums = [3, 2, 10, -2, 7, 6] x = 3 y = 1, then the output will be 22, as the sublist with length 3 we select [3, 2, 10] and for the other we select [7].To solve this, we will follow these steps −P := a list with single element 0for each x in A, doinsert (last element of ... Read More

400 Views
Suppose we have a list of numbers called nums and another value k. We have to find the maximum sum of elements that we can delete, given that we must pop exactly k times, where each pop can be from the left or the right end.So, if the input is like nums = [2, 4, 5, 3, 1] k = 2, then the output will be 6, as we can delete 2 and the 4.To solve this, we will follow these steps −window := sum of all numbers from index 0 through k - 1ans := windowfor i in range ... Read More

185 Views
Suppose we have a list of numbers called nums. Let us consider an operation where we can select a number, then remove it and increase our score by the sum of the number and its two adjacent numbers. If we can perform this operation as many times as we want as long as we do not select the first or the last number in the list. We have to find the maximal score possible.So, if the input is like nums = [2, 3, 4, 5, 6], then the output will be 39, as we can select 5, then sum will ... Read More

442 Views
Suppose we have a 2D matrix, where each row and column is sorted in non-decreasing order, we have to check whether given target is present inside it or not.So, if the input is like243034316632And target = 31, then the output will be TrueTo solve this, we will follow these steps −col := column size of matrix - 1for i in range 0 to row size of matrix, dowhile matrix[i, col] > target and col >= 0, docol := col - 1if matrix[i, col] is same as target, thenreturn Truereturn FalseLet us see the following implementation to get better understanding −Example Live ... Read More

178 Views
Suppose we have a 2D matrix, where each row and column is sorted in non-decreasing order, we have to find the nth smallest number.So, if the input is like243034316632And n = 4, then the output will be 6.To solve this, we will follow these steps −lst := a new listfor each row i in matrix, dofor each cell j in i, doinsert j at the end of lstsort the list lstreturn lst[n]Let us see the following implementation to get better understanding −Example Live Democlass Solution: def solve(self, matrix, n): lst = [] for i ... Read More

234 Views
Suppose we have a binary matrix. We have to find the same matrix, but each cell's value will be the Manhattan distance to the nearest 0. We can assume at least one 0 exists in the matrix.So, if the input is like101101110then the output will be101101210as only the bottom left cell has distance of 2 to the nearest 0.To solve this, we will follow these steps −m := row size of matrix, n := column size of matrixfor y in range 0 to m, dofor x in range 0 to n, doif matrix[y, x] is non-zero, thenmatrix[y, x] := infinityfor ... Read More

1K+ Views
Suppose we have a list of coins and another value amount, we have to find the number of combinations there are that sum to amount. If the answer is very large, then mod the result by 10^9 + 7.So, if the input is like coins = [2, 5] amount = 10, then the output will be 2, as we can make these combinations − [2, 2, 2, 2, 2], [5, 5]To solve this, we will follow these steps −m := 10^9 + 7dp := a list of size same as amount + 1, and fill it with 0dp[0] := 1for ... Read More

256 Views
Suppose we have a list of numbers called nums and another value target. We have to find the lowest sum of pair of numbers that is larger than target.So, if the input is like nums = [2, 4, 6, 10, 14] target = 10, then the output will be 12, as we pick 2 and 10To solve this, we will follow these steps −sort the list numsn := size of numsanswer := 10^10i := 0, j := n - 1while i < j, doif nums[i] + nums[j] > target, thenanswer := minimum of answer and (nums[i] + nums[j])j := j ... Read More

2K+ Views
To push values into an associative array, use the brackets [] []. At first create an associative array −$details= array ( 'id' => '101', 'name' => 'John Smith', 'countryName' => 'US' );The PHP code is as follows to insert values −Example Live Demo OutputArray ( [studentDetails] => Array ( [0] => Array ( [id] => 101 [name] => John Smith [countryName] => US ) ) )