<?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>DEV Community: Pathipati Suresh Kumar</title>
    <description>The latest articles on DEV Community by Pathipati Suresh Kumar (@sureshpathipati).</description>
    <link>https://dev.to/sureshpathipati</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F223535%2Fc97fe45a-ee59-4896-8861-1306409c04f1.jpg</url>
      <title>DEV Community: Pathipati Suresh Kumar</title>
      <link>https://dev.to/sureshpathipati</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sureshpathipati"/>
    <language>en</language>
    <item>
      <title>Binary Gap of a Number</title>
      <dc:creator>Pathipati Suresh Kumar</dc:creator>
      <pubDate>Wed, 04 Sep 2019 15:52:05 +0000</pubDate>
      <link>https://dev.to/sureshpathipati/binary-gap-of-a-number-1931</link>
      <guid>https://dev.to/sureshpathipati/binary-gap-of-a-number-1931</guid>
      <description>&lt;p&gt;when ever I think of interview, this question always have a JamesBond entry in my mind.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Question:&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;Given a number, you need to convert it to binary format and then find the maximum no.of zero's between two 1's(binary gap)&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Approach:&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;One among Many&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Convert the number to binary&lt;/li&gt;
&lt;li&gt;Have a loop and find the maximum no.of zero's b/w 1's&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  &lt;em&gt;1. Convert to binary&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;1) Well this can be done using basic mathematics(My Approach)&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
   2) Ruby has inbuilt function "to_s(&amp;lt; format &amp;gt;)" for Fixnum(Best, Clear and Easy)&lt;br&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  &lt;em&gt;2. Find the BinaryGap of the string&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;1) My approach was having a loop inside a loop, and iterate over the entire string/array and making it more complex. Yes, its horrible :) and we can do this in a better way.&lt;/p&gt;

&lt;p&gt;2) Here, we will be checking the entire string. we decide what to do when 1's and 0's are encountered.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
 

&lt;p&gt;&lt;strong&gt;[Note]&lt;/strong&gt;&lt;br&gt;
FlagVariable is required only when we intentionally pass a binary string starting with zero.&lt;/p&gt;

&lt;p&gt;Let me know, if this can be done differently ;)&lt;/p&gt;

&lt;p&gt;Thanks for your time.&lt;/p&gt;

</description>
      <category>career</category>
      <category>ruby</category>
    </item>
  </channel>
</rss>
