
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

679 Views
Consider a country that is represented as a tree with N nodes and N-1 edges. Now each node represents a town, and each edge represents a road. We have two lists of numbers source and dest of size N-1. According to them the i-th road connects source[i] to dest[i]. And the roads are bidirectional. We also have another list of numbers called population of size N, where population[i] represents the population of the i-th town. We are trying to upgrade some number of towns into cities. But no two cities should be adjacent to each other and every node adjacent ... Read More

486 Views
Suppose we have a list of numbers called nums and another value k, we have to find the number of subsets in the list that sum up to k. If the answer is very large then mod this with 10^9 + 7So, if the input is like nums = [2, 3, 4, 5, 7] k = 7, then the output will be 3, as We can choose the subsets [2,5],[3,4] and [7].To solve this, we will follow these steps −dp := a list of size (k + 1) and fill with 0dp[0] := 1m := 10^9 + 7for i in range 0 to size of nums - 1, dofor j in range k down to 0, decrease by 1, doif nums[i]

865 Views
Suppose we have a list of cartesian points [(x1, y1), (x2, y2), ..., (xn, yn)], that is representing a polygon, and also have two values x and y, we have to check whether (x, y) lies inside this polygon or on the boundary.So, if the input is like points = [(0, 0), (1, 3), (4, 4), (6, 2), (4, 0)] pt = (3, 1)then the output will be TrueTo solve this, we will follow these steps −ans := Falsefor i in range 0 to size of polygon - 1, do(x0, y0) := polygon[i](x1, y1) := polygon[(i + 1) mod size ... Read More

180 Views
Suppose we have a list of numbers called nums, we have to find the length of the longest increasing subsequence and we are assuming the subsequence can wrap around to the beginning of the list.So, if the input is like nums = [6, 5, 8, 2, 3, 4], then the output will be 5, as the longest increasing subsequence is [2, 3, 4, 6, 8].To solve this, we will follow these steps −a := make a list of size twice of nums and fill nums twiceans := 0for i in range 0 to size of nums, dodp := a new ... Read More

210 Views
Suppose we have a N x N binary matrix where 0 is for empty cells and 1 is a blocked cells, we have to find the number of ways to choose N empty cells such that every row and every column has at least one chosen cells. If the answer is very large return result mod 10^9 + 7So, if the input is like000000010then the output will be 4, as we have following configurations (where x is a selected cell) −To solve this, we will follow these steps −n := size of matrixDefine a function f() . This will take ... Read More

361 Views
Suppose we have a n x 3 matrix where each row contains three fields [src, dest, id] this means the bus has route from src to dest. It takes one unit of money to get on a new bus, but if we stay on the same bus we have to pay one unit only. We have to find the minimum cost necessary to take the bus from location 0 to the final stop (largest location). If there is no solution return -1.So, if the input is like010120230351502then the output will be 2, as we can take the 0 at location ... Read More

3K+ Views
Suppose we have a string that represents a mathematical expression with (+, -, *, /) Here / is representing integer division, we have to evaluate and return the result without using any built-in function.So, if the input is like s = "2+3*5/7", then the output will be 4, as 2 + ((3 * 5) / 7) = 4To solve this, we will follow these steps −s := reverse the given stringDefine a function get_value().sign := 1if s is not empty and last element of s is same as "-", thendelete last element from ssign := -1value := 0while s is ... Read More

228 Views
Suppose we have a list of numbers called nums that is representing the stock prices of a company in chronological order and we also have another value k, we have to find the maximum profit we can make from up to k buys and sells (We must buy before sell, and sell before buy).So, if the input is like prices = [7, 3, 5, 2, 3] k = 2, then the output will be 3, as we can buy at 3, then sell at 5, again buy at 2, and sell at 3.To solve this, we will follow these steps ... Read More

250 Views
Suppose we have a list of numbers nums and another value k. Here the items at nums[i] represents the costs of landing at index i. If we start from index 0 and end at the last index of nums. In each step we can jump from some position X to any position up to k steps away. We have to minimize the sum of costs to reach last index, so what will be the minimum sum?So, if the input is like nums = [2, 3, 4, 5, 6] k = 2, then the output will be 12, as we can ... Read More

288 Views
Suppose we have a list of numbers called prices and that is representing the stock prices of a company in chronological order, we have to find the maximum profit we can make from buying and selling that stock at most two times. We have to buy first then sell.So, if the input is like prices = [2, 6, 3, 4, 2, 9], then the output will be 11, as we can buy at price 2, then sell at 6, again buy at 2, and sell at 9.To solve this, we will follow these steps −first_buy := -inf, first_sell := -infsecond_buy ... Read More