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
Server Side Programming Articles - Page 1423 of 2650
341 Views
Suppose we have a list of numbers called nums, we have to rearrange its order to form the largest possible number and return that as a string.So, if the input is like nums = [20, 8, 85, 316], then the output will be "88531620".To solve this, we will follow these steps −Define an array tempfor each item i in nums:insert i into temp as stringsort the array temp based on lexicographic sequence (check for two strings a, b when a concatenate b is larger than b concatenate a or not)for each string s in temp:res := res concatenate sreturn resLet ... Read More
699 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
498 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]
161 Views
Suppose we have a binary matrix. Now consider an operation where we take one cell and flip it and all its neighboring cells (up, down, left, right). We have to find the minimum number of operations required such that matrix contains only 0s. If there is no solution, then return -1.So, if the input is like0010then the output will be 3.To solve this, we will follow these steps −Define an array dir of size: 4 x 2 := {{1, 0}, {0, 1}, { - 1, 0}, {0, - 1}}const int inf = 10^6Define a function getPos(), this will take i, ... Read More
880 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
193 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
220 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
752 Views
Suppose we have two lists costs_from and costs_to of same size where each index i represents a city. It is making a one-way road from city i to j and their costs are costs_from[i] + costs_to[j]. We also have a list of edges where each edge contains [x, y] indicates there is already a one-way road from city x to y. If we want to go to any city from city 0, we have to find the minimum cost to build the necessary roads.So, if the input is like costs_from = [6, 2, 2, 12] costs_to = [2, 2, 3, ... Read More
377 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