Company: Deutsche bank_3nov

Difficulty: medium

Problem Statement

Operations to Reduce Binary String to Zero Problem Description You are given a string S of length N that encodes a non-negative integer V in binary. You may repeatedly transform V using two possible operations: If V is odd, subtract 1 from it; If V is even, divide it by 2. You keep applying these operations until V reaches 0. For example, if string S = "011100" , its initial value V is 28. V changes as follows: V = 28 , which is even: divide by 2 to get 14; V = 14 , which is even: divide by 2 to get 7; V = 7 , which is odd: subtract 1 to get 6; V = 6 , which is even: divide by 2 to get 3; V = 3 , which is odd: subtract 1 to get 2; V = 2 , which is even: divide by 2 to get 1; V = 1 , which is odd: subtract 1 to get 0. Reducing V to 0 took seven operations in total. Write a function: int solution(string &S); that, given a string S of N characters holding a binary encoding of the starting value V , returns the number of operations after which V reaches 0. Examples Example 1: Input: S = "0

More Deutsche bank_3nov OA questionsInterview experiences