text: Maximum frequency of a remainder modulo 2 i | C ++ implementation of the approach ; Binary representation of the digits ; Function to return the maximum frequency of s modulo with a power of 2 ; Store the binary representation ; Convert the octal to binary ; Remove the LSB ; If there is 1 in the binary representation ; Find the number of zeroes in between two 1 's in the binary representation ; Driver code
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; const string bin [ ] = { "000" , "001" , "010" , "011" , "100" , "101" , "110" , "111" } ; int maxFreq ( string s ) { string binary = " " ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { binary += bin [ s [ i ] - '0' ] ; } binary = binary . substr ( 0 , binary . length ( ) - 1 ) ; int count = 1 , prev = -1 , i , j = 0 ; for ( i = binary . length ( ) - 1 ; i >= 0 ; i -- , j ++ ) if ( binary [ i ] == '1' ) { count = max ( count , j - prev ) ; prev = j ; } return count ; } int main ( ) { string octal = "13" ; cout << maxFreq ( octal ) ; return 0 ; }