<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Shreeja Mehta</title>
    <description>The latest articles on Forem by Shreeja Mehta (@shreejamehta).</description>
    <link>https://forem.com/shreejamehta</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F957360%2Fe6302947-410d-41d0-91bb-794755798a69.jpeg</url>
      <title>Forem: Shreeja Mehta</title>
      <link>https://forem.com/shreejamehta</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/shreejamehta"/>
    <language>en</language>
    <item>
      <title>Leetcode Daily Question - 2864. Maximum Odd Binary Number</title>
      <dc:creator>Shreeja Mehta</dc:creator>
      <pubDate>Fri, 01 Mar 2024 18:11:07 +0000</pubDate>
      <link>https://forem.com/shreejamehta/leetcode-daily-question-2864-maximum-odd-binary-number-180b</link>
      <guid>https://forem.com/shreejamehta/leetcode-daily-question-2864-maximum-odd-binary-number-180b</guid>
      <description>&lt;p&gt;When given a binary string containing at least one '1', the task is to rearrange the bits to create the maximum odd binary number possible. To achieve this, it's essential to understand the optimal positioning of the '1's within the string to maximize the resulting value.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding the Approach
&lt;/h2&gt;

&lt;p&gt;The key to forming the greatest odd number lies in placing the '1's in a specific manner. By placing the rest of the '1's in front of the string and having the final '1' at the end, we can ensure that the resulting binary number is the maximum odd number possible.&lt;/p&gt;

&lt;h3&gt;
  
  
  Formulating the Result
&lt;/h3&gt;

&lt;p&gt;The resulting string can be expressed as:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;(total-1 '1's) + (total '0's) + '1'&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;By employing this strategy, it becomes possible to rearrange the given binary string to form the maximum odd binary number, optimizing the positioning of the '1's to achieve the desired result.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Solution&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;public:&lt;/span&gt;
    &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;maximumOddBinaryNumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;c1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;c0&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;auto&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="sc"&gt;'1'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;c1&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;c0&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c1&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sc"&gt;'1'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="sc"&gt;'0'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sc"&gt;'1'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>learning</category>
      <category>cpp</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
