Company: Titan

Difficulty: easy

Problem Statement

You are given an array a of length n . Time is measured in seconds, numbered 1, 2, 3, ... . During the x -th second you may perform the following operation at most once : Choose any set of distinct indices of the array (the set may be empty). Add 2^(x-1) to every element at a chosen index. Different seconds may use completely different sets of indices, and you may also skip a second entirely without changing anything. An array is nondecreasing if a[1] <= a[2] <= ... <= a[n] . Determine the minimum number of seconds T needed so that, after the operations performed during seconds 1 through T , the array becomes nondecreasing. If the array is already nondecreasing, the answer is 0 . You must answer several independent test cases. Input Format The first line contains a single integer t — the number of test cases. For each test case: The first line contains a single integer n — the length of the array. The second line contains n space-separated integers a[1], a[2], ..., a[n] . Outp

More Titan OA questionsInterview experiences