<?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: Leslie Rodriguez</title>
    <description>The latest articles on DEV Community by Leslie Rodriguez (@rarrrleslie).</description>
    <link>https://dev.to/rarrrleslie</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%2F206528%2F460a3c5d-0b87-425c-a5f4-967c945dd97b.png</url>
      <title>DEV Community: Leslie Rodriguez</title>
      <link>https://dev.to/rarrrleslie</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rarrrleslie"/>
    <language>en</language>
    <item>
      <title>Procrastination Station</title>
      <dc:creator>Leslie Rodriguez</dc:creator>
      <pubDate>Sat, 02 Jan 2021 00:41:09 +0000</pubDate>
      <link>https://dev.to/rarrrleslie/procrastination-station-4d87</link>
      <guid>https://dev.to/rarrrleslie/procrastination-station-4d87</guid>
      <description>&lt;p&gt;Wanna know how to get from Procrastination Station to Inspiration Nation with concentration and organization? 🤔 &lt;/p&gt;

&lt;p&gt;🔆 You must first have the realization. 🔆&lt;/p&gt;

&lt;h3&gt;
  
  
  Here is the situation:
&lt;/h3&gt;

&lt;p&gt;You have that feature that is due this Friday. It is Tuesday, you made your branch yesterday but let's be honest, you haven't even started. &lt;/p&gt;

&lt;p&gt;Whatcha been doing all day? Arguably you have been productive, you cleaned your entire house, you planned dinner for tonight and tomorrow night and what the heck might as well plan Friday night's dinner or you will end up ordering take out again. Then you started some laundry cause that's just gonna pile up if you don't. You sat down, opened your code editor, then remembered you have been meaning to organize your closet. &lt;/p&gt;

&lt;p&gt;Now finally at your computer, you &lt;strong&gt;realized&lt;/strong&gt; you have been on Twitter for 45 minutes. &lt;/p&gt;

&lt;h3&gt;
  
  
  But this is good! You're at that million-dollar moment. 🔥
&lt;/h3&gt;

&lt;p&gt;With the &lt;em&gt;realization&lt;/em&gt; that you have been unfocused, whether you feel guilty because you decided you needed to clean out your closet randomly or you just spent 45 minutes on Twitter, the trick is to quickly get over that guilty feeling as soon as you realize you are realizing it. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/12cwiPXDWlOmNa/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/12cwiPXDWlOmNa/giphy.gif" alt="guy having a realization"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You &lt;strong&gt;must&lt;/strong&gt; celebrate this realization before the next step: &lt;/p&gt;

&lt;h3&gt;
  
  
  Stop it
&lt;/h3&gt;

&lt;p&gt;Either stop scrolling or finish organizing that closet but remember to feel GOOD about that. Because it doesn't matter that you wasted time, what matters is that you realized it, stopped what you are doing, (or if you must, finish what you started first... but then seriously stop) and &lt;strong&gt;&lt;em&gt;feel&lt;/em&gt;&lt;/strong&gt; that feeling of winning. That feeling will give you that slight push to move towards your goal. &lt;/p&gt;

&lt;h3&gt;
  
  
  Inspiration Nation
&lt;/h3&gt;

&lt;p&gt;Now, with this feeling, you are at Inspiration Nation. Use this feeling of inspiration to plan. &lt;/p&gt;

&lt;p&gt;Like my favorite artist, Big Sean wrote: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Look, think about it, close your eyes, dream about it&lt;br&gt;
Tell your team about it, go make million-dollar schemes about it&lt;/p&gt;

&lt;p&gt;-- &lt;cite&gt;One Man Can Change The World&lt;/cite&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Most likely, if you already felt even a little guilty, you know the thing you have been putting off and what you need to do. In this case, the plan is already there, but if this is not the case, well, figure it out, dude. &lt;/p&gt;

&lt;h3&gt;
  
  
  Have an Organization Revelation.
&lt;/h3&gt;

&lt;p&gt;Get organized the way you like to. Maybe it's clearing your desk of trash, making a detailed to-do list, or closing all those dang browser tabs. Beware this step doesn't take longer than 5 or 10 minutes. If you hit 15 minutes you are now back where you started: Procrastination Station. &lt;/p&gt;

&lt;h3&gt;
  
  
  Focused Attention and A Concentration Sensation
&lt;/h3&gt;

&lt;p&gt;Getting yourself organized will allow you to start working. You can focus now. Congrats, your work will be done with a concentration sensation. &lt;/p&gt;

</description>
      <category>productivity</category>
      <category>focus</category>
      <category>motivation</category>
      <category>work</category>
    </item>
    <item>
      <title>Get in Loser, We're Doing Linked-List Logic</title>
      <dc:creator>Leslie Rodriguez</dc:creator>
      <pubDate>Sat, 31 Oct 2020 09:53:05 +0000</pubDate>
      <link>https://dev.to/rarrrleslie/get-in-loser-we-re-doing-linked-list-logic-dki</link>
      <guid>https://dev.to/rarrrleslie/get-in-loser-we-re-doing-linked-list-logic-dki</guid>
      <description>&lt;p&gt;Okay, raise your hand if you have ever been personally victimized by these ridiculously convoluted little data structures. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/fx8uNchQRlUcajKW0G/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/fx8uNchQRlUcajKW0G/giphy.gif" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Okay, maybe that’s a bit dramatic but it sure &lt;em&gt;felt like&lt;/em&gt; I was being victimized the first few (or 30) times I had to come up with a solution in an impossible amount of time. Let's add to that the pressure of being watched and judged for the inability to follow one's own logic. If you're like me you may have cried a little... a couple of times.  &lt;/p&gt;

&lt;p&gt;Nevertheless, in the words of my favorite philosopher, Ron Swanson, &lt;em&gt;“Keep your tears in your eyes, where they belong.”&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;I have written this article for beginners who have trouble visualizing the solution, turning it into pseudocode, and then coding a working solution. &lt;/p&gt;

&lt;p&gt;In it, I will cover what a linked list is, why it’s so confusing, and how to skillfully yet artfully arrange nodes and their pointers to solve one of the most common linked list problems I have seen so far: reversing a linked list. &lt;/p&gt;

&lt;p&gt;Let's start by taking a look at the following class definition of a linked list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Definition for singly-linked list.

class ListNode:    
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
* This is the python way of defining a linked list, straight from Leetcode’s &lt;a&gt;Add Two Numbers&lt;/a&gt; challenge
 





&lt;h2&gt;
  
  
  So, is it a 'ListNode' or List of Nodes?
&lt;/h2&gt;

&lt;p&gt;To make a linked list, you need something that can hold a value and point to other values. We call these instances list-nodes or just nodes. &lt;/p&gt;

&lt;p&gt;The name “linked list” itself is confusing because it is &lt;em&gt;not&lt;/em&gt; in fact, a list at all. At least not like a list in Python or an array in JavaScript, which both include indexes and are therefore ordered. &lt;/p&gt;

&lt;p&gt;A linked list is a way of storing values and linking them together like a chain. It can be defined as a class with a head and a tail property which correspond to the starting and ending nodes, but this is not always so.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Technically, just one node is a linked list, even if it’s pointed to a &lt;code&gt;None&lt;/code&gt; value.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For example, using the class from above, let’s create a linked list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;linked_list = ListNode(1)

print(linked_list) 
# this is what it would look like printed to the terminal: 
# &amp;lt;class ListNode object&amp;gt; 

# to access the data
linked_list.val   # 1
linked_list.next  # None
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Drawn out, our linked_list looks like this:&lt;br&gt;&lt;br&gt;
&lt;code&gt;# 1 -&amp;gt; None&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Seriously, what is this? A list for ANTS? It needs to be at least... THREE TIMES BIGGER THAN THIS?!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Haha, nope that’s all it takes. You can keep creating nodes and then connect them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node2 = ListNode(2)
linked_list.next = node2
# or simply: 
node2.next = ListNode(3)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if we draw it out, our entire linked_list looks like this: &lt;br&gt;
&lt;code&gt;# 1 -&amp;gt; 2 -&amp;gt; 3 -&amp;gt; None&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;But &lt;code&gt;linked_list&lt;/code&gt; is still just a single node with a &lt;code&gt;val (1)&lt;/code&gt;, and a &lt;code&gt;next (node2)&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;A lot of the confusion comes from the fact that there is no list, so getting the value of all the nodes is not as easy as writing a good ol’ &lt;em&gt;for loop&lt;/em&gt;. Most times all you get is just a reference to a starting node. As long as you have the starting node, you can still move through all the nodes by &lt;em&gt;traversing&lt;/em&gt;.  &lt;/p&gt;
&lt;h2&gt;
  
  
  Traversing a Linked List
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;For Loops? Where we’re going we don’t need for loops!&lt;/strong&gt; Given a starting node, to get to the next node, the node after next, and all the other nodes, what you need to do is traverse.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# start with the given node
curr = node     

    # while loop that keeps going as long as current never becomes NONE
    while curr is not None:

        # do something with this node's value or pointer
        # this will be where we do the logic to reverse
        print(curr.value)       

        curr = curr.next # set the curr pointer to next node
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This gem of a while loop is something you will use often in many LL problems, so practice it and know it like the back of your hand! &lt;/p&gt;

&lt;h2&gt;
  
  
  Reversing A linked List
&lt;/h2&gt;

&lt;p&gt;If you google the algorithm for this you might see something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Initialize three pointers prev as NULL, curr as head and next as NULL.
Iterate through the linked list. In loop, do following. 
// Before changing next of current, 
// store next node 
next = curr-&amp;gt;next
// Now change next of current 
// This is where actual reversing happens 
curr-&amp;gt;next = prev 
// Move prev and curr one step forward 
prev = curr 
curr = next
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
*Algorithm From Geeksforgeeks.org:





&lt;p&gt;DO NOT make the mistake I did thinking you can solve this a few times and remember it later. You might find yourself in an interview saying: “FIRST, I made some pointers. Then I simply set this pointer to that pointer’s next and prev to current’s next, or was it prev to next’s next.. Shoot I can’t remember...”.  &lt;/p&gt;

&lt;p&gt;Really the only thing you need to remember is that to reverse a linked list iteratively you need THREE different pointers.&lt;/p&gt;

&lt;p&gt;Then, even if you can’t remember how to reverse exactly, you can just figure it out by moving the pointers around. Practice “figuring it out” without looking at the pseudocode as many times as you can. For me, “figuring it out” means visualizing it. &lt;/p&gt;

&lt;h2&gt;
  
  
  How to Visualize the Solution and Turn it into Code
&lt;/h2&gt;

&lt;p&gt;1.) Figure out your starting point i.e if you have 1 &amp;gt; 2 -&amp;gt; None, the starting values will be &lt;br&gt;
&lt;code&gt;prev = None, curr = 1, and next =  None&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---qJl72fI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8c4dhqtdhrrsbwwpt2xd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---qJl72fI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8c4dhqtdhrrsbwwpt2xd.png" alt="starting point visual aid figure 1"&gt;&lt;/a&gt;&lt;/p&gt;
 figure 1 



&lt;p&gt;2.) Draw it out, EVERYTHING. Including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Nodes with their next pointers (I drew them as circles with black arrows)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;All None values&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;PREV, CURR, and NEXT pointers ( I color-coded mine )&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;prev, curr, and next values at the start of each loop&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;while condition at the start of each loop&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kTadWv3---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/o74x178j0athfy1keqhb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kTadWv3---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/o74x178j0athfy1keqhb.png" alt="visual aid figure 2"&gt;&lt;/a&gt;&lt;/p&gt;
 figure 2



&lt;p&gt;3.) Figure out what the arrows need to point to in order for the list to be reversed. You should only move the arrows and not the nodes. Before you move around arrows, make sure you can write this step as code. For example, in this case, we know that all colored pointers are where they need to be except the &lt;code&gt;next&lt;/code&gt; one. If we want the red arrow to point to 2, the logic for that would be ‘next = curr.next’. &lt;br&gt;
Since we are not dealing with lists, we can’t just say &lt;code&gt;next + 1&lt;/code&gt; or &lt;code&gt;next[1] = 20&lt;/code&gt; or anything like that.  We can only “move around", or get to nodes, using the pointers we have.&lt;/p&gt;

&lt;p&gt;4.) Before moving on to a new loop update the values (the ones at the bottom of figure 2) for prev, curr, and next values to wherever the corresponding arrow is pointing to.&lt;/p&gt;

&lt;p&gt;5.) At the start of a new loop, go through the code you wrote for the first loop, making sure the logic still applies and achieves the desired effect.&lt;/p&gt;

&lt;p&gt;Check out my video of how I do this. &lt;/p&gt;

&lt;p&gt;Really follow each step and then try drawing it out yourself without any help. It helps to have a whiteboard or a pencil because you will need to erase and redraw arrows. This takes practice, patience, and iterations. Before I recorded this video I erased my steps and started over at least 3 or 4 times. Sometimes your logic works in the first loop but then when you keep going you realize the pseudocode won’t work further down the line. That’s okay, just take your time and take a 5 min break if you feel like you're getting nowhere. &lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/YPZvuWnol34"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You’ll notice at the end there, the starting node of our reversed list is now accessible by the &lt;code&gt;prev&lt;/code&gt; pointer variable. This is the value we want to return. &lt;/p&gt;

&lt;h2&gt;
  
  
  Let’s go ahead and code it out!
&lt;/h2&gt;

&lt;p&gt;The code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution:
    def reverseList(self, head):
        prev = None 
        curr = head
        nxt = None
        while curr is not None:
            nxt = curr.next

            # // This is where actual reversing happens 
            curr.next = prev

            prev = curr
            curr = nxt

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

&lt;/div&gt;



&lt;p&gt;There is one edge case that might break our code and that is if we pass in a None value, or in other words an empty list, as a parameter. Let's fix that with a conditional.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution:
    def reverseList(self, head):
        if head is None:
            return head

        prev = None 
        curr = head
        nxt = None

        while curr is not None:
            nxt = curr.next

            # This is where actual reversing happens 
            curr.next = prev

            # then we update values to traverse
            prev = curr
            curr = nxt

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Linked list problems are common interview challenges, they can be very confusing at first, so practice working with linked lists as much as you can. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Do not try to memorize the logic, it may cause confusion, and moreover, it won't always be the same exact challenge. The best thing to do is get comfortable drawing out nodes and making visual aids. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When reversing a list iteratively, you need 3 pointers: PREV, CURR, and NEXT. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you haven’t watched Mean Girls, you are missing out on an iconic film, and you should watch it! Only after mastering linked list reversals, that is. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope you found this article helpful and enjoyed my pop culture movie references! I’m almost all out of clever ways to fit in movie quotes but I’ll leave you with an age-old classic that has absolutely nothing to do with linked lists or Mean Girls. &lt;em&gt;It doesn’t even go here, so it can’t sit with us!&lt;/em&gt; &lt;br&gt;
Okay, really, that was the (second to) last one.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Life moves pretty fast. If you don’t stop and look around once in a while, you could miss it.&lt;br&gt;
Ferris Bueller’s Day Off&lt;/em&gt;&lt;/p&gt;

</description>
      <category>reversingalinkedlist</category>
      <category>python</category>
      <category>beginners</category>
      <category>pseudocode</category>
    </item>
  </channel>
</rss>
