Swap Nodes [Algo]
A binary tree is a tree which is characterized by one of the following properties: It can be empty (null). It contains a root node only. It contains a root node with a left subtree, a right subtree, or both. These subtrees are also binary trees. In-order traversal is performed as Traverse the left subtree. Visit root. Traverse the right subtree. For this in-order traversal, start from the left child of the root node and keep exploring the left subtree until you reach a leaf. When you
View Solution →Pairs
Given an array of integers and a target value, determine the number of pairs of array elements that have a difference equal to the target value. Function Description Complete the pairs function below. pairs has the following parameter(s): int k: an integer, the target difference int arr[n]: an array of integers Returns int: the number of pairs that satisfy the criterion Input Format The first line contains two space-separated integers n and k, the size of arr and the targe
View Solution →Triple sum
Given 3 arrays a, b , c of different sizes, find the number of distinct triplets ( p , q , r ) where p is an element of a, written as , , and , satisfying the criteria: p <= q and q > = r . Function Description Complete the triplets function in the editor below. It must return the number of distinct triplets that can be formed from the given arrays. triplets has the following parameter(s): a, b, c: three arrays of integers . Input Format The first line contains 3 integers lena
View Solution →Minimum Time Required
You are planning production for an order. You have a number of machines that each have a fixed number of days to produce an item. Given that all the machines operate simultaneously, determine the minimum number of days to produce the required order. For example, you have to produce goal = 10 items. You have three machines that take machines = [2, 3, 2 ] days to produce an item. The following is a schedule of items produced: Day Production Count 2 2 2 3 1
View Solution →Maximum Subarray Sum
We define the following: A subarray of array a of length n is a contiguous segment from a[ i ] through a[ j ] where 0 <= i <= j < n. The sum of an array is the sum of its elements. Given an n element array of integers, a, and an integer, m , determine the maximum value of the sum of any of its subarrays modulo m. For example, Assume a = [1, 2, 3 ]and m = 2 . The following table lists all subarrays and their moduli: sum %2 [1] 1 1 [2] 2 0 [3] 3 1 [1,2] 3 1 [2,3] 5 1 [1,2
View Solution →