Company: Visa

Difficulty: easy

Problem Statement

Minimum Split Into Valid Powers of Two A valid power of two is a power of two whose exponent is at least 1 , that is, one of 2, 4, 8, 16, 32, ... The value 2^0 = 1 is not a valid power of two. For a positive integer x , a valid split of size k is a collection of k positive integers whose sum is exactly x and which satisfies all of the following: exactly k - 1 of the numbers are valid powers of two; the remaining number, called the base , is strictly less than 4 ; exactly one number of the whole collection is strictly less than 4 . Numbers in a split may repeat, and their order does not matter. Note that 2 is itself strictly less than 4 , so the last rule limits which valid powers of two a split may actually use. You are given an array a of n positive integers. For every element a[i] , report the minimum possible size k of a valid split of a[i] , or -1 if a[i] has no valid split at all. Function Description Complete the function minValidSplits in the editor, with the following parameter

More Visa OA questionsInterview experiences