<?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: Tshihab07</title>
    <description>The latest articles on Forem by Tshihab07 (@tshihab).</description>
    <link>https://forem.com/tshihab</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%2F890188%2F9270184f-bd3f-4882-9b34-749e30a33292.png</url>
      <title>Forem: Tshihab07</title>
      <link>https://forem.com/tshihab</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/tshihab"/>
    <language>en</language>
    <item>
      <title>Replacing a substring in a string with another string using python without built-in function</title>
      <dc:creator>Tshihab07</dc:creator>
      <pubDate>Wed, 12 Jul 2023 18:43:15 +0000</pubDate>
      <link>https://forem.com/tshihab/replacing-a-substring-in-a-string-with-another-string-using-python-without-built-in-function-3hea</link>
      <guid>https://forem.com/tshihab/replacing-a-substring-in-a-string-with-another-string-using-python-without-built-in-function-3hea</guid>
      <description>&lt;p&gt;"""&lt;br&gt;
suppose a text &lt;strong&gt;&lt;em&gt;txt&lt;/em&gt;&lt;/strong&gt; is given. we want to replace the first occurrence of the pattern &lt;strong&gt;&lt;em&gt;P1&lt;/em&gt;&lt;/strong&gt; by another pattern &lt;strong&gt;&lt;em&gt;P2&lt;/em&gt;&lt;/strong&gt;.&lt;br&gt;
&lt;strong&gt;REPLACE(txt, P1, P2)&lt;/strong&gt;&lt;br&gt;
"""&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def REPLACE(txt, p1, p2):
    if p1 not in txt:
        return "Pattern not found"

    # getting index of the pattern
    idx = txt.find(p1)

    # initialize variables to store new string
    temp_txt = ""
    new_txt = ""


    # deleting substring from the text
    for i in range(len(txt)):
        if i &amp;lt; idx or i &amp;gt;= idx + len(p1):
            temp_txt += txt[i]


    # adding p2 in txt as replacement
    for i in range(len(temp_txt)):
        if i == idx-1:
            new_txt += temp_txt[i]

            for j in range(len(p2)):
                new_txt += p2[j]

        else:
            new_txt += temp_txt[i]


    return new_txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>python</category>
      <category>pythonfunction</category>
      <category>replacestringalgorithm</category>
    </item>
    <item>
      <title>Hackerrank - Apple and Orange Solution in Python</title>
      <dc:creator>Tshihab07</dc:creator>
      <pubDate>Tue, 12 Jul 2022 17:30:05 +0000</pubDate>
      <link>https://forem.com/tshihab/hackerrank-apple-and-orange-solution-in-python-5fik</link>
      <guid>https://forem.com/tshihab/hackerrank-apple-and-orange-solution-in-python-5fik</guid>
      <description>&lt;p&gt;step - 1: Get maximum between apple and orange array&lt;/p&gt;

&lt;p&gt;step - 2: iterate over the maximum&lt;/p&gt;

&lt;p&gt;step - 3: check the array indexes and if True add the fruit's position with the tree location (a or b) so that we get the actual position of the fruit&lt;/p&gt;

&lt;p&gt;step - 4: nested if condition for the actual position of the fruit is in between the house range (s and t) and if true the count will be increased&lt;/p&gt;

&lt;p&gt;Step - 5: print the output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def countApplesAndOranges(s, t, a, b, apples, oranges):
    # Write your code here
    apple_count = 0
    orange_count = 0

    max_length = max(len(apples), len(oranges))

    for idx in range(max_length):
        if idx &amp;lt; len(apples):
            count = apples[idx] + a
            if s &amp;lt;= count &amp;lt;= t:
                apple_count += 1

        if idx &amp;lt; len(oranges):
            count = oranges[idx] + b
            if s &amp;lt;= count &amp;lt;= t:
                orange_count += 1

    print(apple_count)
    print(orange_count)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>python</category>
      <category>hacckerrank</category>
      <category>problemsolving</category>
      <category>challenge</category>
    </item>
    <item>
      <title>Hackerrank - Sherlock and Array Solution in Python</title>
      <dc:creator>Tshihab07</dc:creator>
      <pubDate>Mon, 11 Jul 2022 10:13:47 +0000</pubDate>
      <link>https://forem.com/tshihab/hackerrank-sherlock-and-array-solution-in-python-9n6</link>
      <guid>https://forem.com/tshihab/hackerrank-sherlock-and-array-solution-in-python-9n6</guid>
      <description>&lt;p&gt;Time Complexity of the program O(n).&lt;br&gt;
if the middle value is q and the sum is p then we can write the equation as follow&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;p + q + p = sum   [as the left and the right sum are same]&lt;/li&gt;
&lt;li&gt;2p = sum - q&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;According to that Mathematical Logic The code can be written as follow:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def balancedSums(arr):
    # Write your code here
    left_sum = 0
    arr_sum = sum(arr)

    for i in arr:

        if (2 * left_sum) == arr_sum - i:
            return "YES"

        left_sum += i

    return "NO"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>python</category>
      <category>array</category>
      <category>hackerrank</category>
      <category>arraysolution</category>
    </item>
  </channel>
</rss>
