title: Maximum binary number a binary string will result to if only one operation is allowed i.e. Right-Rotate By K-Bits where K = [0, Length of String]
body: <p>Suppose you have a binary string <code>S</code> and you are only allowed to do one operation i.e. <code>Right-Rotate by K-bits</code> where <code>K = [0, Length of the string]</code>. Write an algorithm that will print the maximum binary-number you can create by the defined process.</p>
  
  <p>For Example:  </p>
  
  <ol>
  <li><code>S = [00101]</code> then maximum value I can get from the process is <code>10100</code> i.e. <code>20</code>.  </li>
  <li><code>S = [011010]</code> then maximum value I can get from the process is <code>110100</code> i.e. <code>52</code>.</li>
  <li><code>S = [1100]</code> then maximum value I can get from the process is <code>1100</code> i.e. <code>12</code>.</li>
  </ol>
  
  <p>The length of the string <code>S</code> has an upper-limit i.e. <code>5*(10^5)</code>.</p>
  
  <p>The idea which I thought of is kind of very naive which is: as we know that when you right-rotate any binary number by <code>1-bit</code>, you get the same binary number after <code>m</code> rotations where <code>m = number of bits required to represent that number</code>.<br>
  So, I right-rotate by <code>1</code> until I get to the number with which I started with and during the process, I keep track of the max-value I encountered and in last I print the max-value.</p>
  
  <p>Is there an efficient approach to solve the problem?</p>
  
  <p><strong>UPD1:</strong> This the source of the problem <a href="https://www.hackerrank.com/contests/mnnit-opc-2k20-2-0/challenges/one-zero-2/problem" rel="nofollow noreferrer"><strong>One-Zero</strong></a>, it all boils down to the statement I have described above.  </p>
  
  <p><strong>UPD2:</strong> As the answer can be huge, the program will print the answer modulo <code>10^9 + 7.</code></p>