Arnab Chakraborty has Published 3734 Articles

Find minimum adjustment cost of an array in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 25-Aug-2020 11:31:24

602 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 ... Read More

Find median of BST in O(n) time and O(1) space in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 25-Aug-2020 11:28:40

593 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 ... Read More

Find maximum sum of triplets in an array such than i < j < k and a[i] < a[j] < a[k] in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 25-Aug-2020 11:05:35

609 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 ... Read More

Find maximum points which can be obtained by deleting elements from array in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 25-Aug-2020 11:02:23

314 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 ... Read More

Find maximum operations to reduce N to 1 in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 25-Aug-2020 10:59:50

305 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 ... Read More

Find maximum N such that the sum of square of first N natural numbers is not more than X in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 25-Aug-2020 10:57:52

243 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 ... Read More

Find maximum length Snake sequence in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 25-Aug-2020 10:54:38

740 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 ... Read More

Find maximum distance between any city and station in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 25-Aug-2020 10:50:44

293 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 ... Read More

Find maximum difference between nearest left and right smaller elements in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 25-Aug-2020 10:49:04

323 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 ... Read More

Find lost element from a duplicated array in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 25-Aug-2020 10:01:10

344 Views

Suppose we have two arrays which are duplicates of each other except one element, so, one element from one of the given arrays is missing, we have to find that missing element.So, if the input is like A = [2, 5, 6, 8, 10], B = [5, 6, 8, 10], ... Read More

Advertisements