Rakuten interview question

Find Binary GAP of zero between an integer for example integer 9 will be represented as 1001, so here binary gap of zero is 2 and so on

Interview Answers

Anonymous

14 Dec 2020

for( int i = 0 ; i < 30 ; ++i ) { }

2

Anonymous

1 Aug 2020

public int solution(int N) { int binaryGap = 0; String binaryString = Integer.toBinaryString(N); char[] characters = binaryString.toCharArray(); int j = 0; Character c; for (int i = 0; i binaryGap ){ binaryGap = j; } j = 0; } } System.out.println(binaryGap); return binaryGap; }