<?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: Chris Kakos</title>
    <description>The latest articles on DEV Community by Chris Kakos (@ch2isk4kos).</description>
    <link>https://dev.to/ch2isk4kos</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%2F483042%2Fa7c8d605-3014-4122-a0ad-2396ed220ec9.png</url>
      <title>DEV Community: Chris Kakos</title>
      <link>https://dev.to/ch2isk4kos</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ch2isk4kos"/>
    <language>en</language>
    <item>
      <title>Leetcode: Longest Substring without Repeating Characters</title>
      <dc:creator>Chris Kakos</dc:creator>
      <pubDate>Thu, 17 Jun 2021 20:26:41 +0000</pubDate>
      <link>https://dev.to/ch2isk4kos/leetcode-longest-substring-without-repeating-characters-3p9c</link>
      <guid>https://dev.to/ch2isk4kos/leetcode-longest-substring-without-repeating-characters-3p9c</guid>
      <description>&lt;h1&gt;
  
  
  Instruction
&lt;/h1&gt;

&lt;p&gt;Given a string &lt;code&gt;s&lt;/code&gt;, find the length of the longest substring without repeating characters.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What is Being Asked?
&lt;/h1&gt;

&lt;p&gt;Write a function that loops through an input string to check for the longest subset of unique characters and return the length of it's size.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;example 1:&lt;/strong&gt; &lt;code&gt;abcdd&lt;/code&gt; would return &lt;code&gt;4&lt;/code&gt; because that's the contiguous amount of unique characters within the contents of the input string.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;example 2:&lt;/strong&gt; &lt;code&gt;bbbbb&lt;/code&gt; would return &lt;code&gt;1&lt;/code&gt; because there is a single unique character.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What Does That Look Like?
&lt;/h1&gt;

&lt;p&gt;I used the &lt;em&gt;Sliding Window&lt;/em&gt; technique with a dynamic resize to accomplish this. A &lt;strong&gt;Sliding Window&lt;/strong&gt; is essentially a process for traversing a data structure to compare or modify its contents. The operation looks similar to how an accordion stretches out and releases in or perhaps the movement of a caterpillar.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffw2gssxjw5cvv7o32chg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffw2gssxjw5cvv7o32chg.png" alt="Sliding Window" width="800" height="672"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Note:
&lt;/h4&gt;

&lt;p&gt;Chrome uses &lt;code&gt;{}&lt;/code&gt; when logging a &lt;code&gt;Set&lt;/code&gt;.&lt;br&gt;
Firefox uses &lt;code&gt;[]&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What Do I Need to Solve?
&lt;/h1&gt;

&lt;p&gt;I begin with an edge case that checks if the input string is valid and return &lt;code&gt;0&lt;/code&gt; if it isn't.&lt;/p&gt;

&lt;p&gt;I chose to use a JavaScript &lt;code&gt;Set&lt;/code&gt; object as the data structure to apply the Sliding Window technique in my solution. A &lt;code&gt;Set&lt;/code&gt; is a collection of unique values of any type. In this case, we'll be working with type&lt;code&gt;string&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To compare and/or modify the characters of the input string from within the Sliding Window, I'll need two pointers.&lt;/p&gt;

&lt;p&gt;I define two variables: &lt;code&gt;i&lt;/code&gt; and &lt;code&gt;j&lt;/code&gt; and set them each to &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I also define a variable: &lt;code&gt;result&lt;/code&gt; that will store the value of the longest substring to return and initialize it to &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The iteration consists of a nested &lt;code&gt;while&lt;/code&gt; loop. The &lt;code&gt;i&lt;/code&gt; pointer drives the process. While &lt;code&gt;i&lt;/code&gt; is less than the size of the string, each iteration will add the value of &lt;code&gt;i&lt;/code&gt; to the &lt;code&gt;Set&lt;/code&gt; as long as it doesn't already exist.&lt;/p&gt;

&lt;p&gt;It then sets the &lt;code&gt;result&lt;/code&gt; value using JavaScripts &lt;code&gt;Math.max()&lt;/code&gt; method. This method returns the greater value of the two integers passed to it. After &lt;code&gt;result&lt;/code&gt; is set, &lt;code&gt;i&lt;/code&gt; increments 1 and the loop continues.&lt;/p&gt;

&lt;p&gt;When &lt;code&gt;i&lt;/code&gt; gets to a value already stored in the &lt;code&gt;Set&lt;/code&gt;, &lt;code&gt;j&lt;/code&gt; will remove the value from the window and increment 1 for the next iteration.&lt;/p&gt;

&lt;p&gt;Once the while loops complete, the function will return the value stored in &lt;code&gt;longestSubstring&lt;/code&gt;.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Solution
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvts2qgf8w067e6700x96.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvts2qgf8w067e6700x96.png" alt="Longest Substring Without Repeating Characters Solution" width="800" height="442"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Time:&lt;/strong&gt; &lt;code&gt;O(n)&lt;/code&gt; where &lt;code&gt;n&lt;/code&gt; is the number of characters in the string.&lt;br&gt;
&lt;strong&gt;Space:&lt;/strong&gt; &lt;code&gt;O(n)&lt;/code&gt; where &lt;code&gt;n&lt;/code&gt; is the length of the &lt;code&gt;Set&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxx6k5svapc4k6shfs1o1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxx6k5svapc4k6shfs1o1.png" alt="Longest Substring Solution Logs" width="800" height="936"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;I hope this explanation of my solution was helpful in your search. This is not the only approach and I am interested to hear other peoples strategy in solving the problem. Feel free to leave a comment and let me know! Thanks for taking the time to read!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>algorithms</category>
      <category>programming</category>
      <category>challenge</category>
    </item>
    <item>
      <title>Leetcode: Add Two Numbers</title>
      <dc:creator>Chris Kakos</dc:creator>
      <pubDate>Wed, 16 Jun 2021 18:55:54 +0000</pubDate>
      <link>https://dev.to/ch2isk4kos/leetcode-add-two-numbers-e6a</link>
      <guid>https://dev.to/ch2isk4kos/leetcode-add-two-numbers-e6a</guid>
      <description>&lt;h1&gt;
  
  
  Instructions
&lt;/h1&gt;

&lt;p&gt;You are given two &lt;strong&gt;non-empty&lt;/strong&gt; linked lists representing two non-negative integers. The digits are stored in &lt;strong&gt;reverse order&lt;/strong&gt;, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.&lt;/p&gt;

&lt;p&gt;You may assume the two numbers do not contain any leading zero, except the number 0 itself.&lt;/p&gt;

&lt;p&gt;Before we breakdown what the problem is asking, let's first discuss what a linked list is.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Linked List
&lt;/h1&gt;

&lt;p&gt;A linear data structure of nodes chained together by pointers whose order is not determined by a physical location in memory. Each node in the list contains a data field and a reference to the next node in the list.&lt;/p&gt;

&lt;p&gt;A linear data structure? Sounds like an array. Yes, but mostly no. Depending on the programming language, arrays tend to be of fixed size--&lt;em&gt;though not the case in JavaScript&lt;/em&gt;. It is also very expensive to modify an array. The space for updating and/or removing elements must be created and shifted depending on which index you're operating on.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;advantages&lt;/strong&gt; of linked lists attribute to their dynamic size and ease of modification, specifically insertion and deletion. &lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;disadvantages&lt;/strong&gt; should be considered as followed: random access is not allowed so you must access elements in sequential order. Extra memory space is required for the pointer on each element of list. Linked lists are not cache friendly being that there is no physical reference point to find a node like an index.&lt;/p&gt;

&lt;p&gt;There are 3 types of linked lists: Singly, Doubly and Circular. We'll be working with a &lt;strong&gt;Singly Linked List&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2F14yriaozqec9j6gjcc29.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F14yriaozqec9j6gjcc29.png" alt="Singly Linked List"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each node is made up of &lt;strong&gt;at least&lt;/strong&gt; two properties: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;the &lt;code&gt;data&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;a &lt;code&gt;pointer&lt;/code&gt; which is a reference to the next node in line.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The first node is referred to as the &lt;code&gt;head&lt;/code&gt;. If a linked list is empty, the value of the &lt;code&gt;head&lt;/code&gt; is &lt;code&gt;null&lt;/code&gt;.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What is Being Asked?
&lt;/h1&gt;

&lt;p&gt;Write a function that accepts two arguments:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;linked list a&lt;/li&gt;
&lt;li&gt;linked list b&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Both input lists contain whole numbers and are pointing in reverse meaning they're moving left bound. We must apply basic mathematics and add them together, then return the sum as its own linked list.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What Does That Look Like?
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fnuzwi8342eolr2alv58j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fnuzwi8342eolr2alv58j.png" alt="Add Two Numbers"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What Do I Need to Solve?
&lt;/h1&gt;

&lt;p&gt;I define 2 variables as pointers: &lt;code&gt;pointerA&lt;/code&gt; and &lt;code&gt;pointerB&lt;/code&gt; and set them to an input &lt;code&gt;list&lt;/code&gt; of their own.&lt;/p&gt;

&lt;p&gt;I define 2 more variables as containers for the node values that we need to add: &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; and set them each to &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I also define a variable to store a value to &lt;code&gt;carry&lt;/code&gt; over 1 like the example above.&lt;/p&gt;

&lt;p&gt;We need to return a new linked list. I define a &lt;code&gt;result&lt;/code&gt; variable and set it to a newly instantiated node list which points the &lt;em&gt;head&lt;/em&gt; of the list. Then create an additional variable to represent the &lt;code&gt;currentNode&lt;/code&gt; being operated on and point it to the &lt;code&gt;result&lt;/code&gt; variable.&lt;/p&gt;

&lt;p&gt;I used a &lt;code&gt;while&lt;/code&gt; loop that runs until &lt;code&gt;pointerA&lt;/code&gt; OR &lt;code&gt;pointerB&lt;/code&gt; is not truthy, meaning that it will continue to loop until both lists run out of nodes. Inside of the while block is a series of conditionals explained in the comments.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Solution
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.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%2F9wjqg2eht2z11bhebkt4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F9wjqg2eht2z11bhebkt4.png" alt="Add Two Numbers Solution List Node Component"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.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%2F0hjz8lzdhbfbndgt82zt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F0hjz8lzdhbfbndgt82zt.png" alt="Add Two Numbers Solution"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;I refactored the variable names to read more explicitly in an effort to make clear what is taking place throughout each iteration. Would you have solved it the same or did you go with a different approach? Do you have any suggestions on a refactor that may work better? Drop a comment! I'm interested to hear what you think.&lt;/p&gt;

&lt;p&gt;As always thank you for reading and I look forward to interacting and sharing more code!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>algorithms</category>
      <category>programming</category>
      <category>challenges</category>
    </item>
    <item>
      <title>Leetcode: Two Sum</title>
      <dc:creator>Chris Kakos</dc:creator>
      <pubDate>Tue, 15 Jun 2021 23:17:20 +0000</pubDate>
      <link>https://dev.to/ch2isk4kos/leetcode-two-sum-2k</link>
      <guid>https://dev.to/ch2isk4kos/leetcode-two-sum-2k</guid>
      <description>&lt;h1&gt;
  
  
  Instructions
&lt;/h1&gt;

&lt;p&gt;Given an array of integers: &lt;code&gt;num&lt;/code&gt; and an integer: &lt;code&gt;target&lt;/code&gt;, return &lt;em&gt;indices&lt;/em&gt; of the two numbers such that they add up to &lt;code&gt;target&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You may assume that each input would have exactly one solution, and you may not use the same element twice.&lt;/p&gt;

&lt;p&gt;You can return the answer in any order.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What is Being Asked?
&lt;/h1&gt;

&lt;p&gt;Write a function that takes two arguments:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;an array of integers&lt;/li&gt;
&lt;li&gt;an integer&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Within the block scope, you need a way to iterate over the values of &lt;code&gt;nums&lt;/code&gt; and add the current index value with each of the remaining indices. If the sum of the current index value and the comparison index value are equivalent to the &lt;code&gt;target&lt;/code&gt; number, the function should return an array containing the position of both indices. If no conditionals equate to the &lt;code&gt;target&lt;/code&gt; number, the function should return &lt;code&gt;false&lt;/code&gt;.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What Does That Look Like?
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7dqs6txm2l1jj6mp8puh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7dqs6txm2l1jj6mp8puh.png" alt="Two Sum Whiteboard" width="712" height="236"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What Do I Need To Solve?
&lt;/h1&gt;

&lt;p&gt;I chose a nested &lt;code&gt;for&lt;/code&gt; loop in my solution to iterate over the input array: &lt;code&gt;nums&lt;/code&gt;. The outer loop keeps track of the current index value and the inner loop compares the comparison index value(s). If the sum of the outer loop index value and the inner index value equal the &lt;code&gt;target&lt;/code&gt; number, it then returns an array with both indices.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Solution
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv6ilpbd0g9oc2rc7vd4l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv6ilpbd0g9oc2rc7vd4l.png" alt="Two Sum Solution" width="800" height="218"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3jz3swm7eilwirsrn4js.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3jz3swm7eilwirsrn4js.png" alt="Two Sum Console" width="800" height="173"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Thank you for taking the time to read. It's with good intent that I share my approach in hopes that it adds a different perspective for anyone looking to get a better understanding of solving algorithmic challenges and building solutions with code. &lt;/p&gt;

&lt;p&gt;If that's the case, let me know! Give it a like, drop a comment or feel free to connect with me on Twitter @&lt;a href="https://twitter.com/ch2isk4kos" rel="noopener noreferrer"&gt;ch2isk4kos&lt;/a&gt;. I'm all about connecting with the community!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>algorithms</category>
      <category>challenge</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
