<?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: julian</title>
    <description>The latest articles on Forem by julian (@juliansjy).</description>
    <link>https://forem.com/juliansjy</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%2F861591%2F6ba3e946-17b4-4b78-bb0e-97a98001c8c8.jpg</url>
      <title>Forem: julian</title>
      <link>https://forem.com/juliansjy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/juliansjy"/>
    <language>en</language>
    <item>
      <title>Best time to buy and sell stock</title>
      <dc:creator>julian</dc:creator>
      <pubDate>Thu, 12 May 2022 19:44:07 +0000</pubDate>
      <link>https://forem.com/juliansjy/best-time-to-buy-and-sell-stock-1mnh</link>
      <guid>https://forem.com/juliansjy/best-time-to-buy-and-sell-stock-1mnh</guid>
      <description>&lt;p&gt;Tried to solve another question from leetcode involing buy and selling a stock at a specific price. The details are outlined below. &lt;/p&gt;

&lt;p&gt;Need some guidance because the code dosen't work but i'm sure my logic is correct here. The comments outline what i am doing step by step for this question.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--muR9kdg3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8hubv2ovrw8wtznbdjah.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--muR9kdg3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8hubv2ovrw8wtznbdjah.jpg" alt="Image description" width="633" height="682"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wngjp-et--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ly16x3gpbs8r7y29e0dd.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wngjp-et--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ly16x3gpbs8r7y29e0dd.jpg" alt="Image description" width="880" height="361"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var maxProfit = function(prices) {
    const buy = Math.min(prices);                   //finding the lowest value/ buy price
    const index = prices.indexOf(buy);              //get the index of the buy price
    let temp = [];                                  //temporary array to store possible sell prices
    for (let i=index; i&amp;lt;prices.length-1; i++) {
        if (prices[i] &amp;gt; prices[index]) {            //iterate for every element in prices later than buy price
            temp.push(prices[i]);                   //add the values to the temp array
        }
    }
    const sell = Math.max(temp);                    //get the highest value in this temp array
    const profit = sell-buy;                        //get profit 
    if (sell == null) {
        return 0;
    }
    return profit;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Merge Two Sorted Lists Problem</title>
      <dc:creator>julian</dc:creator>
      <pubDate>Thu, 12 May 2022 17:44:33 +0000</pubDate>
      <link>https://forem.com/juliansjy/merge-two-sorted-lists-problem-l36</link>
      <guid>https://forem.com/juliansjy/merge-two-sorted-lists-problem-l36</guid>
      <description>&lt;p&gt;Trying to solve Leetcode problem 21 - Merge 2 sorted lists. Heres the problem below and my own attempt which dosen't work. If anyone can help explain to me the flaw in my logic because it dosen't work :(. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0pElztfe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/43i9f1cjrg43mshum4y1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0pElztfe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/43i9f1cjrg43mshum4y1.jpg" alt="Image description" width="624" height="708"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;`var mergeTwoLists = function(list1, list2) {&lt;br&gt;
    const final = [];&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (let i=0; i&amp;lt;list1.length; i++) {
    for (let j=0; j&amp;lt;list2.length; j++) {
       if (list2[j] &amp;gt; list1[i]) {
           final.push(list1[i]);
       } else if (list1[i] &amp;gt; list2[j]) {
           final.push(list2[j]);
       } else if (list1[i] == list2[j]) {
           final.push(list1[i], list2[j]);
       }
    }
}
return final;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;};`&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
