
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

490 Views
Suppose we have an array of jobs with different time requirements, there are k different persons to assign jobs and we also have how much time t an assignee takes to do one unit of the job. We have to find the minimum time to complete all jobs with following constraints.An assignee can be assigned only the contiguous jobs.Two assignees cannot share or perform a single job.So, if the input is like k = 4, t = 5, job = {12, 6, 9, 15, 5, 9}, then the output will be 75 as we get this time by assigning [12], ... Read More

547 Views
Suppose we have an array of positive numbers; we replace each element from that array array so that the difference between two adjacent elements in the array is either less than or equal to a given target. Now, we have to minimize the adjustment cost, so the sum of differences between new value and old value. More precisely, we minimize ∑|A[i] – Anew[i]| where i in range 0 to n-1, here n is denoted as size of A and Anew is the array with adjacent difference less than or equal to target.So, if the input is like [56, 78, 53, ... Read More

526 Views
Suppose we have Binary Search Tree(BST), we have to find median of it. We know for even number of nodes, median = ((n/2th node + (n+1)/2th node) /2 For odd number of nodes, median = (n+1)/2th node.So, if the input is likethen the output will be 7To solve this, we will follow these steps −if root is same as None, thenreturn 0node_count := number of nodes in the treecount_curr := 0current := rootwhile current is not null, doif current.left null, thencount_curr := count_curr + 1if node_count mod 2 is not 0 and count_curr is same as(node_count + 1) /2, thenreturn ... Read More

563 Views
Suppose we have an array of positive numbers, there are n elements in that array, we have to find the maximum sum of triplet (ai + aj + ak ) such that 0 A[i], thensecond_max := maximum of second_max, A[j]if first_max and second_max is non-zero, thenres := maximum of res, first_max + A[i] + second_maxreturn resExampleLet us see the following implementation to get better understanding − Live Demodef get_max_triplet_sum(A) : n = len(A) res = 0 for i in range(1, (n - 1)) : first_max = 0 second_max = 0 ... Read More

267 Views
Suppose we have an array A with N elements, we also have two integers l and r where, 1≤ ax ≤ 10^5 and 1≤ l≤ r≤ N. Taking an element from the array say ax and remove it, and also remove all elements equal to ax+1, ax+2 … ax+R and ax-1, ax-2 … ax-L from that array. By doing this it will cost ax points. We have to maximize the total cost after removing all of the elements from the array.So, if the input is like A = [2, 4, 3, 10, 5], l = 1, r = 2, then ... Read More

259 Views
Suppose we have two numbers P and Q and they form a number N = (P!/Q!). We have to reduce N to 1 by performing maximum number of operations possible. In each operation, one can replace N with N/X when N is divisible by X. We will return the maximum number of operations that can be possible.So, if the input is like A = 7, B = 4, then the output will be 4 as N is 210 and the divisors are 2, 3, 5, 7.To solve this, we will follow these steps −N := 1000005factors := an array of ... Read More

199 Views
Suppose we have a given integer X, we have to find the maximum value N so that the sum of first N natural numbers should not exceed the value X.So, if the input is like X = 7, then the output will be 2 as 2 is the maximum possible value of N, for N = 3, the sum of the series will exceed X = 7 So, 1^2 + 2^2 + 3^2 = 1 + 4 + 9 = 14.To solve this, we will follow these steps −Define a function sum_of_squares() . This will take Nres :=(N *(N + ... Read More

645 Views
Suppose we have a grid of numbers; we have to find a snake sequence and return it. If there are multiple snake sequence, then return only one. As we know a snake sequence is made using adjacent numbers in the grid so for each number, the number on the right-hand side or the number below it is either +1 or -1 its value. So, if current value is in grid cell (a, b), we can either move right (a, b+1) if that number is ± 1 or move below (a+1, b) if that number is ± 1.So, if the input ... Read More

249 Views
Suppose we have N number of cities, and they are numbered from 0 to N-1 and we also have the cities in which stations are located, we have to find the maximum distance between any city and its nearest station. We have to keep in mind that the cities with stations can be given in any order.So, if the input is like N = 6 and stations = [2, 4], then the output will be 2To solve this, we will follow these steps −station_present := a list of size N, and fill with Falsefor each city in station, dostation_present[city] := ... Read More

264 Views
Suppose we have an array of integers; we have to find the maximum absolute difference between the nearest left and the right smaller element of each of the elements in the array. If there is no smaller element on the right-hand side or left-hand side of any element then we will put zero as the smaller element.So, if the input is like A = [3, 5, 9, 8, 8, 10, 4], then the output will be 4 as left elements L = [0, 3, 5, 5, 5, 8, 3], right elements R = [0, 4, 8, 4, 4, 4, 0], ... Read More