<?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: Sachin Nayak</title>
    <description>The latest articles on Forem by Sachin Nayak (@sachin_nayak_5db3184afd7f).</description>
    <link>https://forem.com/sachin_nayak_5db3184afd7f</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%2F2273138%2Ff8bbbd7b-fb01-42ca-aebd-528fe20e4f5e.png</url>
      <title>Forem: Sachin Nayak</title>
      <link>https://forem.com/sachin_nayak_5db3184afd7f</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/sachin_nayak_5db3184afd7f"/>
    <language>en</language>
    <item>
      <title>Solving Plus Minus Problem in Python (HackerRank ) .</title>
      <dc:creator>Sachin Nayak</dc:creator>
      <pubDate>Thu, 28 Aug 2025 06:43:53 +0000</pubDate>
      <link>https://forem.com/sachin_nayak_5db3184afd7f/solving-plus-minus-problem-in-python-hackerrank-style--45hi</link>
      <guid>https://forem.com/sachin_nayak_5db3184afd7f/solving-plus-minus-problem-in-python-hackerrank-style--45hi</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flwkr7fzpgdsq05ncarpl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flwkr7fzpgdsq05ncarpl.png" alt=" " width="300" height="168"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Problem Description:&lt;br&gt;
Given an array of integers, calculate the ratios of its elements that are positive, negative, and zero. Print the decimal value of each fraction on a new line with 6 places after the decimal.&lt;/p&gt;

&lt;p&gt;Solution:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def plusMinus(arr):
    n = len(arr)  # Total number of elements
    pos = sum(1 for x in arr if x &amp;gt; 0)  # Count positives
    neg = sum(1 for x in arr if x &amp;lt; 0)  # Count negatives
    zero = n - pos - neg  # Remaining are zeros

    # Print ratios with 6 decimal places
    print(f"{pos / n:.6f}")
    print(f"{neg / n:.6f}")
    print(f"{zero / n:.6f}")


# Example usage:
arr = list(map(int, input("Enter the elements of the array separated by space: ").split()))
plusMinus(arr)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example Run : &lt;br&gt;
Input:&lt;br&gt;
-4 3 -9 0 4 1&lt;/p&gt;

&lt;p&gt;Output:&lt;br&gt;
0.500000&lt;br&gt;
0.333333&lt;br&gt;
0.166667&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How the Solution Works&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;1.Count the elements by type&lt;/strong&gt;&lt;br&gt;
Go through the array and count how many numbers are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Positive (greater than 0)&lt;/li&gt;
&lt;li&gt;Negative (less than 0)&lt;/li&gt;
&lt;li&gt;Zero&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2.Calculate ratios&lt;/strong&gt;&lt;br&gt;
Divide each count by the total number of elements in the array.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Positive ratio = (number of positive elements) ÷ (total elements)&lt;/li&gt;
&lt;li&gt;Negative ratio = (number of negative elements) ÷ (total elements)&lt;/li&gt;
&lt;li&gt;Zero ratio = (number of zeros) ÷ (total elements)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3.Format the output&lt;/strong&gt;&lt;br&gt;
Print each ratio on a new line with exactly 6 decimal places.&lt;/p&gt;

</description>
      <category>python</category>
      <category>hackerrank</category>
      <category>coding</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
