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
Programming Articles - Page 1763 of 3366
98 Views
Suppose we have a range of cost from lowCost to upCost and another range of quantity from lowQuant to upQuant, we have to check whether we can find the given ratio r where r=cost/quantity, and lowCost ⇐ cost ⇐ upCost and lowQuant ⇐ quantity ⇐ upQuant.So, if the input is like lowCost = 2, upCost = 10, lowQuant = 3, upQuant = 9 and r = 3, then the output will be True as the cost = r * quantity = 3 * 3 = 9 where cost is in range [1, 10] and quantity is in [2, 8]To solve ... Read More
120 Views
Suppose we have binary tree; we have to check whether the given vertical level of the binary tree is sorted or not. When two nodes are overlapping, check they are in sorted sequence in the level they belong.So, if the input is like l = -1then the output will be True, as elements in level -1 are 3, 7 and they are sorted.To solve this, we will follow these steps −if root is null, thenreturn Trueprevious_value := -infcurrent_level := 0current_node := a new tree node with value 0Define one dequeue named qinsert (root, 0) at the end of qwhile q ... Read More
336 Views
Suppose we have a given undirected graph; we have to check whether it contains an independent set of size l. If there is any independent set of size l then return Yes otherwise No.We have to keep in mind that an independent set in a graph is defined as a set of vertices which are not directly connected to each other.So, if the input is like L = 4, then the output will be yesTo solve this, we will follow these steps −Define a function is_valid() . This will take graph, arrfor i in range 0 to size of arr, ... Read More
525 Views
Suppose we have n pair of points; we have to find four points so that they can generate a square whose sides are parallel to x and y axes otherwise return "not possible" If we can find more than one square then select the one with whose area is maximum.So, if the input is like n = 6, points = [(2, 2), (5, 5), (4, 5), (5, 4), (2, 5), (5, 2)], then the output will be 3, points are (2, 2) (5, 2) (2, 5) (5, 5)To solve this, we will follow these steps −my_map := a new mapfor ... Read More
226 Views
Suppose we have an array of distinct numbers where each number lies in the range [1, N], the array size is (N-4) and no single element is repeated. So, we can understand four numbers, from 1 to N, are missing in the array. We have to find these 4 missing numbers in sorted manner.So, if the input is like A =[2, 8, 4, 13, 6, 11, 9, 5, 10], then the output will be [1, 3, 7, 12]To solve this, we will follow these steps −temp_arr := an array of size 4 with all 0sfor i in range 0 to ... Read More
103 Views
Suppose we have a first term (A) and common difference (d) of an AP series, and we also have a prime number P, we have to find the position of the first element in the given AP which is the a multiple of the given prime number P.So, if the input is like A = 3, D = 4, P = 5, then the output will be 3 as fourth term of the given AP is a multiple of the prime number 5. So, first term = 3, second term = 3+4 = 7, third term = 3+2*4 = 11 ... Read More
277 Views
Suppose we have a number l and a monotonic increasing sequence f(m), where f(m) = am + bm [log2(m)] + cm^3 and (a = 1, 2, 3, …), (b = 1, 2, 3, …), (c = 0, 1, 2, 3, …)Here [log2(m)] is the log to the base 2 and round the value down. so, if m = 1, the value is 0.if m = 2-3, the value is 1.if m = 4-7, the value is 2.if m = 8-15, the value is 3. and so, onwe have to find the value m such that f(m) = l, if l ... Read More
200 Views
Suppose we have an array of n different numbers; n can be 32, 000 at max. The array may have duplicate entries and we do not know what is the value of n. Now if we have only 4-Kilobytes of memory, how would display all duplicates in the array?So, if the input is like [2, 6, 2, 11, 13, 11], then the output will be [2, 11] as 2 and 11 appear more than once in given array.To solve this, we will follow these steps −Create one byte-array type data structure bit_arr, it has following methodsDefine constructor This will take ... Read More
316 Views
Suppose we have a square matrix of order m x m; we have to find all the distinct elements common to all rows of the given matrix.So, if the input is like13215417153243615215412152643221942215then the output will be [2, 4, 15]To solve this, we will follow these steps −Define a function sortRows() . This will take matrixn := count of rowsfor i in range 0 to n, dosort the list matrix[i]In the main method, do the following −n := count of rowssortRows(matrix)current_idx := a list of size n, fill with 0for i in range 0 to n, docurrent_idx[i] := 0f := 0while ... Read More
247 Views
Suppose we have two arrays A and B of n integers, now consider an array C, where the i-th number will be d*A[i] + B[i] and here d is any arbitrary real number. We have to find d such that array C has maximum number of zeros. Also return the number of zeros.So, if the input is like A = [15, 40, 45] and B = [4, 5, 6], then the output will be d = -0.266666, number of zeros will be 1To solve this, we will follow these steps −n := size of Amy_map := a new mapcount := ... Read More