Arnab Chakraborty has Published 4293 Articles

Partition Array for Maximum Sum in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 12:06:21

1K+ Views

Suppose we have an integer array A, we have to partition the array into (contiguous) subarrays of length at most K. After partitioning, each subarray has their values changed to become the maximum value of that subarray. We have to find the largest sum of the given array after partitioning. ... Read More

Minimum Flips to Make a OR b Equal to c in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 11:59:36

662 Views

Suppose we have 3 positives numbers a, b and c. We have to find the minimum flips required in some bits of a and b to make (a OR b == c ). Here we are considering bitwise OR operation.The flip operation consists of change any single bit 1 to ... Read More

Sum of Nodes with Even-Valued Grandparent in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 11:51:56

179 Views

Suppose we have a binary tree, we have to find the sum of values of nodes with even-valued grandparent. (A grandparent of a node is the parent of its parent, if it exists.). If there are no such nodes with an even-valued grandparent, then return 0. So if the tree ... Read More

Binary Tree Coloring Game in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 11:47:13

523 Views

Suppose there are two players play a turn-based game on a binary tree. We have the root of this binary tree and the number of nodes n in the tree. Here n is odd, and each node has a distinct value from 1 to n. At first, the first player ... Read More

Decrease Elements To Make Array Zigzag in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 11:43:20

398 Views

Suppose we have an array nums of integers, a move operation is actually choosing any element and decreasing it by 1. An array A is a zigzag array if either 1 or 2 is satisfied −Every even-indexed element is greater than adjacent elements, So. A[0] > A[1] < A[2] > ... Read More

Matrix Block Sum in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 11:33:32

459 Views

Suppose we have one m * n matrix called mat and an integer K, we have to find another matrix answer where each answer[i][j] is the sum of all elements mat[r][c] for i - K

XOR Queries of a Subarray in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 11:30:17

265 Views

Suppose we have the array arr of positive integers and the array queries where queries[i] = [Li, Ri], for each query the i compute the XOR of elements from Li to Ri (that is, arr[Li] XOR arr[Li+1] xor ... xor arr[Ri] ). We have to find the array containing the ... Read More

Jump Game III in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 11:26:25

432 Views

Suppose we have an array of non-negative integers arr, we are initially positioned at start index of the array. When we are present at index i, we can jump to i + arr[i] or i - arr[i], check if we can reach to any index with value 0. We have ... Read More

All Elements in Two Binary Search Trees in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 11:22:51

263 Views

Suppose we have two binary search trees, we have to return a list of values, that has all elements present in these trees, and the list elements will be in ascending order. So if the trees are like −Then the output will be [0, 1, 1, 2, 3, 4].To solve ... Read More

Connecting Cities With Minimum Cost in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Apr-2020 11:17:17

416 Views

Suppose there are N cities numbered from 1 to N. We have connections, where each connection [i] is [city1, city2, cost] this represents the cost to connect city1 and city2 together. We have to find the minimum cost so that for every pair of cities, there exists a path of ... Read More

Advertisements