<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by ISHAN UPADHYAY on Medium]]></title>
        <description><![CDATA[Stories by ISHAN UPADHYAY on Medium]]></description>
        <link>https://medium.com/@ishanupadhyay412?source=rss-e4071348b5c3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3139zMofNgv_YjHQ1I4wWA.png</url>
            <title>Stories by ISHAN UPADHYAY on Medium</title>
            <link>https://medium.com/@ishanupadhyay412?source=rss-e4071348b5c3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 18:10:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ishanupadhyay412/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[What Is a Golden Path in Platform Engineering? Why Modern Engineering Teams Are Building Them]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-snippet">As engineering organisations grow, something interesting happens.</p><p class="medium-feed-link"><a href="https://medium.com/@ishanupadhyay412/what-is-a-golden-path-in-platform-engineering-why-modern-engineering-teams-are-building-them-4a42d7b9f5a3?source=rss-e4071348b5c3------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@ishanupadhyay412/what-is-a-golden-path-in-platform-engineering-why-modern-engineering-teams-are-building-them-4a42d7b9f5a3?source=rss-e4071348b5c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a42d7b9f5a3</guid>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[cicd-tools]]></category>
            <category><![CDATA[platform-engineering]]></category>
            <dc:creator><![CDATA[ISHAN UPADHYAY]]></dc:creator>
            <pubDate>Sun, 04 Oct 2026 11:49:50 GMT</pubDate>
            <atom:updated>2026-10-04T11:49:50.148Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[The Trinity Knot of Software Engineers]]></title>
            <link>https://medium.com/@ishanupadhyay412/the-trinity-knot-of-software-engineers-bfd382608fd4?source=rss-e4071348b5c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/bfd382608fd4</guid>
            <category><![CDATA[loop]]></category>
            <category><![CDATA[documentation]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[ISHAN UPADHYAY]]></dc:creator>
            <pubDate>Sun, 07 Sep 2025 14:51:32 GMT</pubDate>
            <atom:updated>2025-09-07T14:53:01.127Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hg7p5wRBEwCXKoEk" /><figcaption>Everything is connected</figcaption></figure><h3>A modern myth about documentation, loops, and eternal confusion</h3><ul><li>“Every engineer has faced it: the doc that leads to another doc that leads back to the same doc.”</li><li>“Code may compile, but documentation is where timelines collapse.”</li><li>“Welcome to the Trinity Knot — where outdated guides, half-written updates, and tribal knowledge intertwine forever.”</li></ul><p>This is the story of one such soul.</p><h3>The Beginning of the Loop</h3><p>A senior engineer with 10 years of experience waved a link at the newest joinee and said confidently:</p><p>“Everything you need is in the documentation.”</p><p>The new hire nodded eagerly. He opened the page, put on his metaphorical armor of curiosity, and began reading.</p><p>Step 1: Done.<br>Step 2: Easy.<br>Step 3: No problem.<br>Step 4: A breeze.</p><p>He grinned and thought to himself,<br> “Oh, this isn’t that hard. I’ve got this!”</p><p>But he had spoken too soon.</p><h3>Step 5: The Betrayal</h3><p>The fifth step shattered his confidence:</p><p><em>“Do not follow the above steps. The process has changed. Please refer to the updated documentation here →”</em></p><p>He clicked.</p><p>The updated doc looked promising, shinier, and more structured. But halfway through, it pointed him to <em>another</em> link for the “final version.”</p><p>He clicked again.</p><p>And, to his horror… he was back at the <strong>original documentation</strong>.</p><p>He had entered a time-space loop of hyperlinks.</p><h3>The Search for Wisdom</h3><p>Confused, the joinee wandered the digital corridors of Confluence, SharePoint, and Notion, desperately seeking an escape. That’s when he encountered a mysterious old engineer.</p><p>The man, with the calmness of someone who had long accepted his fate, said:</p><p>“Everything is connected, my child. Code, docs, and tribal knowledge — three threads, forever intertwined. You must find the right person if you wish to escape.”</p><p>The newbie’s eyes widened. Finally, a mentor!</p><p>The old engineer shared a link with full confidence. The newbie clicked…</p><p>…and was dropped back into the same cursed documentation.</p><p>Thus, the <strong>second knot</strong> was tied.</p><h3>The Trinity Revealed</h3><p>It is said there are three knots:</p><ul><li>The first knot is the <strong>outdated documentation</strong> no one dares to delete.</li><li>The second knot is the <strong>new-but-incomplete documentation</strong> written in a rush during a release.</li><li>The third knot is the <strong>knowledge locked inside senior engineers’ heads</strong>, passed down orally like ancient folklore.</li></ul><p>Together, they form the eternal <strong>Trinity Knot of Software Engineering</strong>.</p><p>No beginning, no end. Just loops, links, and confusion.</p><h3>The Moral of the Knot</h3><p>The new joinee never truly escaped. In time, he too became a senior engineer. And when a fresh face joined the company, he smiled knowingly and said the same words once spoken to him:</p><p>“Everything you need is in the documentation.”</p><p>And thus, the Trinity Knot remained unbroken.</p><p>⚡ <em>Because in software engineering, knowledge doesn’t disappear… it just gets version-controlled into different timelines.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bfd382608fd4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why GitOps is Gaining Popularity in the Software Industry]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-snippet">In recent years, GitOps has become a buzzword in the software development and DevOps communities. It&#x2019;s not just a trend but a&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@ishanupadhyay412/why-gitops-is-gaining-popularity-in-the-software-industry-7cbacc7087e5?source=rss-e4071348b5c3------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@ishanupadhyay412/why-gitops-is-gaining-popularity-in-the-software-industry-7cbacc7087e5?source=rss-e4071348b5c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/7cbacc7087e5</guid>
            <category><![CDATA[problem-solving]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[gitops]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[argo-cd]]></category>
            <dc:creator><![CDATA[ISHAN UPADHYAY]]></dc:creator>
            <pubDate>Mon, 02 Dec 2024 14:31:31 GMT</pubDate>
            <atom:updated>2024-12-02T14:32:41.241Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Understanding Persistent Volumes (PV) and Persistent Volume Claims (PVC) in Kubernetes]]></title>
            <link>https://medium.com/@ishanupadhyay412/understanding-persistent-volumes-pv-and-persistent-volume-claims-pvc-in-kubernetes-9c24a08cc287?source=rss-e4071348b5c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c24a08cc287</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[ISHAN UPADHYAY]]></dc:creator>
            <pubDate>Fri, 18 Oct 2024 16:01:35 GMT</pubDate>
            <atom:updated>2024-10-18T16:01:35.646Z</atom:updated>
            <content:encoded><![CDATA[<p>Kubernetes (K8s) is an orchestration platform designed for managing containerized applications at scale. One of the key challenges when working with containers is managing storage — specifically, ensuring that storage persists across container restarts and reschedules. Kubernetes addresses this challenge with <strong>Persistent Volumes (PV)</strong> and <strong>Persistent Volume Claims (PVC)</strong>.</p><p>In this blog, we’ll explore what PVs and PVCs are, their importance in stateful applications, how they differ from ephemeral storage, and how storage classes streamline the provisioning of storage.</p><h4>What is a Persistent Volume (PV)?</h4><p>A <strong>Persistent Volume (PV)</strong> is a piece of storage in a Kubernetes cluster that has been provisioned by an administrator or dynamically created using storage classes (more on this later). A PV exists independently of the pod lifecycle, meaning data stored in a PV can persist beyond the life of any container or pod that uses it.</p><p>Unlike <strong>ephemeral storage</strong>, which only lasts as long as the pod is running, a PV provides a stable, long-term storage solution for stateful applications such as databases, log storage, and data processing apps.</p><p>A PV can be backed by several types of storage such as local storage, cloud storage services (like AWS EBS, Google Persistent Disk), or network file systems (like NFS).</p><h4><strong>Key Characteristics of PV</strong></h4><p><strong>Decoupled from pods</strong>: A PV exists independently of pods, ensuring that the storage remains available even when pods are deleted or rescheduled.</p><p><strong>Managed by Kubernetes</strong>: Once provisioned, Kubernetes handles the lifecycle of the PV, ensuring that it is mounted to the right pods when requested.</p><pre>apiVersion: v1<br>kind: PersistentVolume<br>metadata:<br>  name: my-pv<br>spec:<br>  capacity:<br>    storage: 10Gi<br>  accessModes:<br>    - ReadWriteOnce<br>  persistentVolumeReclaimPolicy: Retain<br>  storageClassName: standard<br>  hostPath:<br>    path: &quot;/mnt/data&quot;</pre><h4>What is a Persistent Volume Claim (PVC)?</h4><p>A <strong>Persistent Volume Claim (PVC)</strong> is a request by a user for storage. Much like a pod consumes resources like CPU and memory, a PVC consumes storage resources. A PVC specifies how much storage is needed and the access mode (e.g., read-write or read-only).</p><p>When a PVC is created, Kubernetes attempts to match the PVC to an available PV based on storage size and access modes. If a suitable PV is found, it binds the claim to the volume, and the pod can then use the claimed storage.</p><pre>apiVersion: v1<br>kind: PersistentVolumeClaim<br>metadata:<br>  name: my-pvc<br>spec:<br>  accessModes:<br>    - ReadWriteOnce<br>  resources:<br>    requests:<br>      storage: 10Gi<br>  storageClassName: standard</pre><h4>Ephemeral Storage vs. Persistent Volumes: Why PVs are Better</h4><h4>Ephemeral Storage</h4><p>Ephemeral storage is the temporary storage available within a container. It exists only for the lifetime of the pod and is lost when the pod is deleted or moved to another node. For stateless applications like web servers or caching layers, ephemeral storage is often sufficient. However, for stateful applications like databases, ephemeral storage is inadequate, as the loss of data on pod termination could lead to system failures and data corruption.</p><h4>Persistent Volumes (PV)</h4><p>Persistent Volumes offer a clear advantage over ephemeral storage by ensuring data continuity, even if the underlying pod is deleted or rescheduled. PVs ensure that data is not tied to a specific node or container instance, making them a must-have for stateful applications that require data durability.</p><p><strong>Key Advantages of PVs over Ephemeral Storage:</strong></p><ol><li><strong>Durability</strong>: PVs remain available even after the pod using them is deleted or rescheduled.</li><li><strong>Resilience</strong>: In case of node failures, the same volume can be reattached to a new pod, ensuring data is not lost.</li><li><strong>Stateful Applications</strong>: PVs are essential for stateful applications that need to retain data between restarts (e.g., MySQL, PostgreSQL).</li><li><strong>Flexibility</strong>: PVs can be backed by diverse storage options, from local SSDs to cloud-based storage services.</li></ol><h4>What Are Storage Classes?</h4><p><strong>Storage Classes</strong> allow administrators to define different classes or tiers of storage within a Kubernetes cluster. Storage classes are useful for managing different types of storage (e.g., SSD, HDD, NFS, cloud-based storage) and automating the dynamic provisioning of PVs. A <strong>StorageClass</strong> defines the type of storage to provision and the configuration parameters for the storage backend (such as replication factor or encryption).</p><p>When a PVC specifies a storageClassName, Kubernetes dynamically provisions a PV with the appropriate storage type. This allows developers to easily request the correct type of storage without needing to understand the underlying infrastructure.</p><pre>apiVersion: storage.k8s.io/v1<br>kind: StorageClass<br>metadata:<br>  name: fast<br>provisioner: kubernetes.io/gce-pd<br>parameters:<br>  type: pd-ssd<br>  replication-type: none<br>reclaimPolicy: Delete</pre><p>In this example, a StorageClass called fast is defined, which provisions Google Compute Engine SSD storage. The provisioner field specifies which storage backend will be used, while the parameters field allows customization based on storage type.</p><h4>How Storage Classes Help</h4><ul><li><strong>Dynamic Provisioning</strong>: Kubernetes automatically provisions a PV when a PVC requests storage. This eliminates the need for pre-provisioning, simplifying cluster management.</li><li><strong>Flexible Tiers</strong>: Storage classes can offer different performance characteristics, such as high IOPS SSDs for databases and cost-effective HDDs for backups.</li><li><strong>Custom Policies</strong>: Each storage class can define custom policies (e.g., encryption, replication) tailored to different use cases.</li></ul><h3>Conclusion</h3><p>Persistent Volumes (PV) and Persistent Volume Claims (PVC) are powerful Kubernetes features that allow for the separation of storage from the lifecycle of individual pods. This decoupling ensures data persistence, which is crucial for stateful applications. When compared to ephemeral storage, PVs provide resilience, durability, and flexibility, making them the go-to solution for managing data in production-grade Kubernetes clusters.</p><p>Storage Classes add an extra layer of flexibility, allowing administrators to manage various types of storage and automatically provision PVs tailored to specific needs. By leveraging these Kubernetes features, you can build robust, scalable, and stateful applications that remain resilient even in dynamic environments. To know more about PVC and ephemeral storage take a look at the <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/">Kubernetes documentation</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c24a08cc287" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Tree Problems: DFS and Backtracking Techniques for Binary Trees]]></title>
            <link>https://medium.com/@ishanupadhyay412/understanding-tree-problems-dfs-and-backtracking-techniques-for-binary-trees-fed3963586d9?source=rss-e4071348b5c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/fed3963586d9</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[ISHAN UPADHYAY]]></dc:creator>
            <pubDate>Thu, 10 Oct 2024 08:13:01 GMT</pubDate>
            <atom:updated>2024-10-11T15:56:49.914Z</atom:updated>
            <content:encoded><![CDATA[<h4>Introduction</h4><p>Solving tree data structure problems can be challenging, but once you understand key techniques like Depth First Search (DFS) and backtracking, even complex problems become easier to handle. Whether you’re tackling problems like finding the maximum depth, diameter, or path sum in a binary tree, these techniques are essential. In this blog, we’ll explore various binary tree problems and how DFS and backtracking help solve them efficiently.</p><h4>Why DFS and Backtracking Work for Tree Problems</h4><p>DFS (Depth First Search) and backtracking are perfectly suited for tree problems due to their ability to traverse and explore each branch deeply before backtracking to explore other branches. Trees, by their very structure, are hierarchical, with parent nodes leading to child nodes, making recursion and DFS naturally fit for their traversal.</p><p><strong>Key Reasons DFS and Backtracking Are Effective:</strong></p><ol><li><strong>Recursive Nature of Trees:</strong><br>Trees inherently have a recursive structure where each node can be seen as the root of its own subtree. DFS capitalizes on this property by recursively exploring each node and its subtrees. This allows us to solve problems by breaking them down into smaller subproblems that involve each node and its children.</li><li><strong>Efficient Path Exploration:</strong><br>DFS explores one path completely before moving to another, making it effective for problems where we need to compute results along a specific path, such as finding maximum paths, counting good nodes, or checking for identical subtrees. This deep exploration is useful for gathering cumulative data (like path sums) along the way.</li><li><strong>Backtracking to Aggregate Results:</strong><br>When we traverse a tree using DFS, we often need to collect results from the subtrees and aggregate them as we move back up to the root. Backtracking ensures that as we return from the recursive call, we can update key metrics like maximum path sums, heights, or diameters. This aggregation is crucial for problems where we need to compare or sum values across multiple subtrees.</li><li><strong>State Preservation:</strong><br>With backtracking, we can preserve and propagate important state information, such as the current path or maximum values encountered so far. For example, in the “Good Nodes in a Binary Tree” problem, we pass down the maximum value encountered along the path so far, allowing each node to decide whether it qualifies as a “good node.”</li><li><strong>Handles Complex Structures with Ease:</strong><br>DFS allows us to manage more complex structures within trees, such as binary trees with varying depths, unbalanced trees, or trees with specific node values. For example, in problems like “Binary Tree Right Side View,” DFS can traverse each level and only pick nodes from the rightmost branch without needing a complex iterative approach.</li><li><strong>Optimal for Searching All Possible Solutions:</strong><br>DFS is an exhaustive search algorithm, which means it explores all possible paths or configurations, making it optimal for problems where we need to check all nodes or paths. It guarantees that no node is left unvisited, ensuring that solutions like finding the diameter of a binary tree or checking identical trees are accurate.</li><li><strong>Memory Efficiency in Trees:</strong><br>Since trees typically have fewer branches than graphs, DFS tends to be memory efficient. The recursion stack only grows as deep as the height of the tree, making it ideal for exploring deep trees without using additional memory for tracking visited nodes (unlike BFS, which requires a queue).</li></ol><p>By leveraging DFS and backtracking, you can solve a wide range of binary tree problems efficiently, from calculating maximum path sums to determining the tree’s diameter or identifying visible nodes from a specific view.</p><h4>Key Binary Tree Problems Solved with DFS</h4><p>Let’s dive into some common binary tree problems that can be solved using DFS and backtracking.</p><p><strong>Maximum Path Sum in a Binary Tree</strong></p><p>This problem involves finding the maximum sum of any path in the tree. A path is defined as any sequence of nodes from some starting node to any node along the tree, including root and leaf nodes.</p><pre>class Solution(object):<br>    def maxPathSum(self, root):<br>        maxsum = [float(&#39;-inf&#39;)]<br>        <br>        def dfs(node):<br>            if node is None:<br>                return 0<br>            leftsum = max(dfs(node.left), 0)<br>            rightsum = max(dfs(node.right), 0)<br>            currsum = node.val + leftsum + rightsum<br>            maxsum[0] = max(maxsum[0], currsum)<br>            return node.val + max(leftsum, rightsum)<br><br>        dfs(root)<br>        return maxsum[0]</pre><p><strong>Diameter of a Binary Tree</strong></p><p>The diameter of a binary tree is the longest path between any two nodes. This path may or may not pass through the root.</p><pre>class Solution(object):<br>    def diameterOfBinaryTree(self, root):<br>        self.diameter = 0<br>        <br>        def dfs(node):<br>            if node is None:<br>                return 0<br>            left = dfs(node.left)<br>            right = dfs(node.right)<br>            self.diameter = max(self.diameter, left + right)<br>            return max(left, right) + 1<br>        <br>        dfs(root)<br>        return self.diameter</pre><p><strong>Maximum Depth of a Binary Tree</strong></p><p>The maximum depth (or height) of a binary tree is the longest path from the root to any leaf.</p><pre>class Solution(object):<br>    def maxDepth(self, root):<br>        if root is None:<br>            return 0<br>        left_depth = self.maxDepth(root.left)<br>        right_depth = self.maxDepth(root.right)<br>        return 1 + max(left_depth, right_depth)</pre><p><strong>Counting Good Nodes in a Binary Tree</strong></p><p>A node is considered “good” if the path from the root to that node has no nodes with a value greater than the current node. The task is to count the total number of good nodes in the binary tree.</p><pre>class Solution(object):<br>    def goodNodes(self, root):<br>        good = [0]<br>        <br>        def dfs(node, max_val):<br>            if node is None:<br>                return 0<br>            if max_val &lt;= node.val:<br>                good[0] += 1<br>            max_val = max(max_val, node.val)<br>            dfs(node.left, max_val)<br>            dfs(node.right, max_val)<br>            return good[0]<br><br>        dfs(root, root.val)<br>        return good[0]</pre><p><strong>Binary Tree Right Side View</strong></p><p>This problem involves finding the right side view of a binary tree. Essentially, you need to return the nodes that are visible when the tree is viewed from the right side.</p><pre>class Solution(object):<br>    def rightSideView(self, root):<br>        rightview = []<br>        <br>        def rightside(node, level):<br>            if node is None:<br>                return<br>            if len(rightview) == level:<br>                rightview.append(node.val)<br>            rightside(node.right, level + 1)<br>            rightside(node.left, level + 1)<br><br>        rightside(root, 0)<br>        return rightview</pre><h4>Common Mistakes to Avoid</h4><ol><li><strong>Forgetting the Base Case</strong>: Always ensure your recursive DFS function includes a base case to handle None nodes. Without it, your code will either run into infinite recursion or throw errors.</li><li><strong>Global Variables Not Updated</strong>: When solving problems like maximum path sum or diameter, make sure to update the global variable that tracks the overall result. Neglecting to do this will yield incorrect results.</li><li><strong>Handling Edge Cases</strong>: For problems involving comparisons (like counting good nodes), remember to handle edge cases such as negative values or single-node trees.</li></ol><h4>Conclusion</h4><p>DFS and backtracking are powerful tools for solving binary tree problems. Whether you’re finding the maximum depth, calculating the diameter, or determining the number of good nodes, these techniques allow you to break down the problem into manageable recursive steps. With consistent practice, you can solve even complex tree problems efficiently.</p><p>If you’re preparing for coding interviews or simply want to strengthen your problem-solving skills, understanding DFS and backtracking is crucial. Apply these techniques, and tree problems will no longer seem daunting.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fed3963586d9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring the Iterator Design Pattern in Linked Lists, Graphs, and Trees]]></title>
            <link>https://medium.com/@ishanupadhyay412/exploring-the-iterator-design-pattern-in-linked-lists-graphs-and-trees-fdaa2a09046b?source=rss-e4071348b5c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/fdaa2a09046b</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[design-thinking]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[object-oriented]]></category>
            <dc:creator><![CDATA[ISHAN UPADHYAY]]></dc:creator>
            <pubDate>Tue, 17 Sep 2024 14:48:59 GMT</pubDate>
            <atom:updated>2024-09-17T14:48:59.871Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*jDJUZXakhNap7FmW5m-8WQ.png" /></figure><p>The <strong>Iterator Design Pattern</strong> is one of the most fundamental design patterns in object-oriented programming, facilitating access to elements of an aggregate object sequentially without exposing its underlying representation. This pattern is particularly useful when working with data structures like <strong>linked lists</strong>, <strong>graphs</strong>, and <strong>trees</strong>, where traversal can be complex due to their non-linear structure.</p><p>Here we will explore how the Iterator Design Pattern applies to <strong>linked lists</strong>, <strong>graphs</strong>, and <strong>trees</strong>, breaking down the pattern’s purpose and usage for each data structure.</p><h4>What is the Iterator Design Pattern?</h4><p>At its core, the <strong>Iterator Pattern</strong> provides a way to access elements of a collection (or an aggregate object) sequentially, without needing to know the internal details of the structure. The pattern typically involves two components:</p><p>1. <strong>Iterator</strong>: Defines the interface for accessing elements.<br>2. <strong>Aggregate</strong>: Defines the collection of elements and provides a way to create the iterator.</p><p>The main advantage of using an iterator is abstraction — it allows us to interact with the collection without knowing its internal data structure.</p><h4><strong>Applying the Iterator Pattern to Linked Lists</strong></h4><p>A <strong>Linked List</strong> is a linear data structure where each element (node) points to the next one. Unlike arrays, the elements of a linked list are not stored contiguously in memory, which makes sequential traversal non-trivial.</p><p>To traverse a linked list, we can implement the Iterator Pattern as follows:</p><p>1. <strong>LinkedList Class</strong>: This class maintains the head pointer and provides the method <em>getIterator()</em> to return a new iterator.<br>2. <strong>LinkedListIterator</strong>: Implements the iterator interface with methods like <em>hasNext()</em> and <em>next()</em> for traversing the list.</p><p>Here’s a simplified version in Python:</p><pre><br>class Node:<br> def __init__(self, value):<br> self.value = value<br> self.next = None</pre><pre>class LinkedListIterator:<br> def __init__(self, head):<br> self.current = head<br><br>def has_next(self):<br> return self.current is not None<br><br>def next(self):<br> if not self.has_next():<br> raise StopIteration<br> value = self.current.value<br> self.current = self.current.next<br> return value<br><br>class LinkedList:<br> def __init__(self):<br> self.head = None<br><br>def add(self, value):<br> new_node = Node(value)<br> new_node.next = self.head<br> self.head = new_node<br><br>def get_iterator(self):<br> return LinkedListIterator(self.head)</pre><p>In this implementation, `LinkedListIterator` handles the traversal, allowing you to fetch elements one by one. The `LinkedList` class hides the complexity of accessing nodes by providing a clean interface for iterating.</p><h4>Applying the Iterator Pattern to Trees</h4><p>A <strong>Tree</strong> is a hierarchical structure consisting of nodes where each node has zero or more children. Common tree traversals include <strong>in-order</strong>, <strong>pre-order</strong>, and <strong>post-order</strong>.</p><p>Using the Iterator Pattern in trees can simplify the traversal by abstracting away the traversal mechanism. Let’s take the example of a binary tree and implement an <strong>in-order traversal</strong> using an iterator.</p><p>1. <strong>Tree Class</strong>: Represents the root of the tree and provides access to an iterator.<br>2. <strong>TreeIterator:</strong> Implements the in-order traversal using recursion or an explicit stack.</p><p>Here’s a simplified Python implementation for **in-order traversal**:</p><pre><br>class TreeNode:<br> def __init__(self, value):<br> self.value = value<br> self.left = None<br> self.right = None</pre><pre>class InOrderTreeIterator:<br> def __init__(self, root):<br> self.stack = []<br> self._push_left(root)<br><br>def _push_left(self, node):<br> while node:<br> self.stack.append(node)<br> node = node.left<br><br>def has_next(self):<br> return bool(self.stack)<br><br>def next(self):<br> if not self.has_next():<br> raise StopIteration<br> node = self.stack.pop()<br> value = node.value<br> if node.right:<br> self._push_left(node.right)<br> return value<br><br>class BinaryTree:<br> def __init__(self, root=None):<br> self.root = root<br>def get_inorder_iterator(self):<br> return InOrderTreeIterator(self.root)</pre><p>This implementation hides the complexity of the in-order traversal inside the <em>InOrderTreeIterator</em> class. The <em>BinaryTree</em> class simply provides access to the iterator, allowing the client to focus on the traversal logic without needing to manage the stack or recursion.</p><h4>Applying the Iterator Pattern to Graphs</h4><p>Graphs are more complex than linked lists or trees, as they can contain cycles and have multiple traversal strategies, such as <strong>Depth-First Search (DFS)</strong> and <strong>Breadth-First Search (BFS)</strong>.</p><p>In a <strong>graph traversal</strong>, the iterator’s role is to visit all nodes in a particular order (DFS or BFS) while ensuring that each node is visited only once. The iterator will abstract away the traversal strategy.</p><p>Let’s implement a <strong>BFS iterator</strong> for a graph using an adjacency list:</p><pre><br>from collections import deque<br><br>class GraphIterator:<br> def __init__(self, graph, start_node):<br>   self.graph = graph<br>   self.queue = deque([start_node])<br>   self.visited = set([start_node])<br><br>def has_next(self):<br> return bool(self.queue)<br><br>def next(self):<br> if not self.has_next():<br>   raise StopIteration<br> node = self.queue.popleft()<br> for neighbor in self.graph[node]:<br>   if neighbor not in self.visited:<br>     self.visited.add(neighbor)<br>   self.queue.append(neighbor)<br> return node<br><br>class Graph:<br> def __init__(self):<br>   self.adjacency_list = {}<br>def add_edge(self, u, v):<br> if u not in self.adjacency_list:<br>   self.adjacency_list[u] = []<br> self.adjacency_list[u].append(v)<br>def get_bfs_iterator(self, start_node):<br> return GraphIterator(self.adjacency_list, start_node)</pre><p>Here, the `GraphIterator` handles the traversal using a **queue** for BFS. It abstracts away the internal mechanics, ensuring that the client only interacts with the iterator interface for the traversal.</p><h4>Why Use the Iterator Pattern for These Data Structures?</h4><p>The Iterator Pattern is particularly useful for complex data structures like <strong>linked lists</strong>, <strong>trees</strong>, and <strong>graphs</strong> because it:</p><p>- <strong>Abstracts traversal logic</strong>: The user does not need to know how the internal structure of the data works. They can simply iterate through elements.<br>- <strong>Supports multiple traversal strategies</strong>: Particularly for trees and graphs, different traversal strategies (DFS, BFS, in-order, post-order) can be implemented as different iterators.<br>- <strong>Promotes encapsulation</strong>: By keeping the traversal logic within the iterator, the underlying structure remains hidden, providing a clean and modular design.<br>- <strong>Reduces coupling</strong>: Users of the iterator are decoupled from the structure’s internal representation, making it easier to modify or extend the structure without affecting the client code.</p><h4>Conclusion</h4><p>The <strong>Iterator Design Pattern</strong> offers an elegant way to traverse complex data structures like <strong>linked lists</strong>, <strong>trees</strong>, and <strong>graphs</strong> without exposing their internal workings. Whether it’s moving linearly through a linked list, recursively through a tree, or searching a graph, iterators offer flexibility and abstraction that simplify the user’s interaction with these structures. By implementing iterators, you make your data structures more reusable, maintainable, and easier to extend.</p><p>The next time you’re working with these data structures, consider leveraging the power of the Iterator Design Pattern for clean and efficient traversal.</p><h4>References:</h4><h4><a href="https://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612?&amp;linkCode=ll1&amp;tag=upliftunleash-20&amp;linkId=3adb7f296a11b896375e401c48f0e7b9&amp;language=en_US&amp;ref_=as_li_ss_tl">Design Patterns: Elements of Reusable Object-Oriented Software</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fdaa2a09046b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding SLO, SLA, and SLI in Site Reliability Engineering (SRE)]]></title>
            <link>https://medium.com/@ishanupadhyay412/understanding-slo-sla-and-sli-in-site-reliability-engineering-sre-5e683a9a62f7?source=rss-e4071348b5c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e683a9a62f7</guid>
            <category><![CDATA[business]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[sre]]></category>
            <category><![CDATA[reliability]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[ISHAN UPADHYAY]]></dc:creator>
            <pubDate>Fri, 06 Sep 2024 06:50:19 GMT</pubDate>
            <atom:updated>2024-09-06T06:50:19.216Z</atom:updated>
            <content:encoded><![CDATA[<p>In today’s digitally connected world, businesses increasingly rely on the smooth functioning of web applications, cloud services, and distributed systems. As these systems grow in complexity, ensuring their reliability, performance, and availability becomes critical. This is where concepts like SLO (Service Level Objective), SLA (Service Level Agreement), and SLI (Service Level Indicator) come into play. These terms are foundational in Site Reliability Engineering (SRE) and are essential for any DevOps or SRE professional to master.</p><p>This blog will explore these terms in detail, breaking down their roles, differences, and how they contribute to building and maintaining reliable systems.</p><h4>Service Level Indicator (SLI)</h4><p><strong>Definition:</strong><br>An SLI is a quantitative measure of some aspect of the level of service provided. It’s a metric used to assess the performance or reliability of a system, typically expressed as a ratio or percentage. SLIs serve as the building blocks for setting objectives and agreements related to service levels.</p><p><strong>Common Examples of SLIs:</strong><br>- <strong>Availability:</strong> The percentage of time a service is operational (uptime).<br>- <strong>Latency:</strong> The response time of a service (e.g., API response times).<br>- <strong>Error Rate:</strong> The ratio of failed requests to successful ones.<br>- <strong>Throughput:</strong> The number of successful transactions processed over a period.</p><p><strong>How SLIs Work:</strong><br>SLIs measure the current state of a service. For instance, if a web service responds to 99,000 requests successfully out of 100,000, the SLI for availability would be 99%. Similarly, if 2% of all requests take more than 200ms, the latency SLI might be represented as 98% of requests are served within 200ms.</p><p><strong>Why SLIs Matter:</strong><br>- SLIs provide data-driven insights into the real-time performance of your system.<br>- They are the basis for monitoring and alerting mechanisms to maintain system health.<br>- SLIs help align the engineering team’s priorities with business objectives.</p><h4>Service Level Objective (SLO)</h4><p><strong>Definition:</strong><br>An SLO is a target or goal for a specific SLI over a defined period. It defines the acceptable level of service a company commits to providing to its customers. Essentially, SLOs set the performance thresholds that the service should meet to be considered reliable.</p><p><strong>Common Examples of SLOs:</strong><br>- <strong>Availability SLO:</strong> “The service must have 99.9% uptime per month.”<br>- <strong>Latency SLO:</strong> “95% of requests must be responded to within 200 milliseconds.”<br>- <strong>Error Rate SLO:</strong> “The system must not exceed a 0.1% error rate over a quarter.”</p><p><strong>How SLOs Work:</strong><br>SLOs are typically determined based on business priorities, customer expectations, and technical feasibility. If your availability SLO is set at 99.9%, it means that over a month (<strong>43,200 minutes</strong>), your service can only be down for a maximum of <strong>43.2 minutes</strong>.</p><p><strong>Why SLOs Matter:</strong><br>- Sets clear goals for system performance, giving teams a defined benchmark.<br>- Helps engineering teams balance the trade-off between feature velocity and system stability.<br>- SLOs offer a realistic promise to customers while still accounting for inevitable failures or downtimes.<br>- They are used to allocate error budgets, which help teams prioritize between building new features and improving system reliability.</p><p><strong>The Concept of Error Budgets:</strong><br>An error budget is the difference between 100% uptime and the SLO. For example, if your SLO is 99.9% uptime, the remaining 0.1% is the “allowed” downtime. Error budgets provide teams with the flexibility to push new changes while staying within acceptable limits. If a team exceeds its error budget, it must focus on reliability rather than releasing new features.</p><h4>Service Level Agreement (SLA)</h4><p><strong>Definition:</strong><br>An SLA is a formal, legal agreement between a service provider and the customer. It defines the level of service expected and outlines the consequences of failing to meet that level. SLAs are usually more rigid than SLOs, as they often involve penalties or financial repercussions for the service provider.</p><p><strong>Common Examples of SLAs:</strong><br>- <strong>Uptime SLA:</strong> “The service provider guarantees 99.9% availability, with a penalty of 5% refund for every 0.1% below that threshold.”<br>- <strong>Response Time SLA:</strong> “Customer support will respond to critical issues within 1 hour.”<br> <br><strong>How SLAs Work:</strong><br>SLAs typically reference SLOs as the promised service level, but they also include the terms of compensation when the SLOs are not met. If a provider fails to meet its SLA (say, if uptime falls below 99.9%), they might have to refund the customer or face other contractual penalties.</p><p><strong>Why SLAs Matter:</strong><br>- SLAs are binding agreements that give customers confidence in the service.<br>- They hold service providers accountable to the promises made to customers.<br>- SLAs ensure transparency by clearly laying out the service level expectations and repercussions for failure.</p><h4>Relationship Between SLOs and SLAs:</h4><p>- SLOs are internal goals for system performance.<br>- SLAs are the external commitments made to customers, often based on the SLOs but typically more conservative.<br> <br>A service may set an SLO of 99.95% uptime internally, but offer an SLA of 99.9% uptime to customers. This buffer allows teams to handle unexpected issues without immediately violating contractual terms.</p><h4>SLO, SLA, and SLI: A Unified Perspective</h4><p><strong>The Connection:</strong><br>- SLIs are the metrics or indicators that measure performance (e.g., uptime, latency, etc.).<br>- SLOs define the targets for these SLIs that the system aims to meet.<br>- SLAs formalize these targets and set legal consequences if the service provider fails to meet them.</p><p>Together, SLIs, SLOs, and SLAs form a comprehensive framework for defining, monitoring, and ensuring the reliability of systems.</p><p>Example:<br>Consider an e-commerce website with the following metrics:<br>- SLI (Availability): Measures how often the website is available (e.g., 99.95%).<br>- SLO (Availability): Sets a goal to maintain 99.95% availability over a month.<br>- SLA: Promises the customer 99.9% availability with a clause that offers financial compensation for downtime beyond this.</p><p>Best Practices for Using SLOs, SLAs, and SLIs</p><p>1. Align SLOs with Business Priorities: Ensure that your SLOs reflect what’s most critical for your users. For instance, if your users care most about speed, focus on latency metrics.<br> <br>2. Set Realistic SLOs: Use historical data to define SLOs that are challenging but achievable. Unrealistic SLOs will lead to frequent failures and frustration.</p><p>3. Monitor SLIs in Real-Time: Use tools like Prometheus and Grafana to continuously monitor your SLIs and set up alerts when they approach the SLO thresholds.</p><p>4. Error Budgets: Use error budgets to manage the balance between new feature development and system reliability. If the error budget is exceeded, focus on improving reliability.</p><p>5. Regularly Review SLAs: Ensure that your SLAs are feasible and match your system’s capabilities. Over-promising can lead to penalties and loss of customer trust.</p><h4>Conclusion</h4><p>In the realm of SRE, SLIs, SLOs, and SLAs are indispensable tools that ensure system reliability while managing customer expectations. SLIs help monitor key performance indicators, SLOs set ambitious but achievable goals, and SLAs formalize commitments to customers with clear consequences for failure. Understanding and implementing these concepts effectively can be the difference between a reliable system and one that struggles to meet its users’ needs.</p><p>By mastering these elements, businesses can build more resilient systems, increase customer satisfaction, and maintain trust — all while continuously improving their services.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e683a9a62f7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Group Anagrams Problem on LeetCode Using Python]]></title>
            <link>https://medium.com/@ishanupadhyay412/group-anagrams-problem-on-leetcode-using-python-94c29f0243b3?source=rss-e4071348b5c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/94c29f0243b3</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[ISHAN UPADHYAY]]></dc:creator>
            <pubDate>Thu, 05 Sep 2024 08:32:19 GMT</pubDate>
            <atom:updated>2024-09-05T08:35:16.183Z</atom:updated>
            <content:encoded><![CDATA[<h4>LeetCode 49</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*jYDNAY6RGiJa_k4mrAtx2w.png" /></figure><p>The <strong>Group Anagrams</strong> problem is a popular coding challenge that appears frequently in coding interviews. It&#39;s an excellent problem to practice your knowledge of <strong>Python dictionaries</strong> and <strong>tuples</strong>. In this blog post, we&#39;ll break down the solution to this problem and help you understand how to group words that are anagrams of each other.</p><h4>Problem Statement</h4><p>Given an array of strings, we need to group the words that are anagrams of each other. Each group of anagrams will be returned as a list of strings. If two words are anagrams, it means they contain the same characters in the same frequency, though the order of characters might differ.</p><p><strong>Example:</strong><br><br>Input: [&quot;eat&quot;, &quot;tea&quot;, &quot;tan&quot;, &quot;ate&quot;, &quot;nat&quot;, &quot;bat&quot;]<br>Output: [[&quot;eat&quot;, &quot;tea&quot;, &quot;ate&quot;], [&quot;tan&quot;, &quot;nat&quot;], [&quot;bat&quot;]]</p><h4><strong>What Are Anagrams?</strong></h4><p>An anagram is when two words contain the same characters with the same frequency. For example, &quot;eat&quot; and &quot;tea&quot; are anagrams because they both contain one &#39;e&#39;, one &#39;a&#39;, and one &#39;t&#39;.</p><h4><strong>Key Insight for the Solution</strong></h4><p>To solve this problem, we need to find a way to <strong>group words based on the frequency of characters</strong>. If two words are anagrams, the count of each character in those words will be exactly the same.</p><h4><strong>Approach</strong></h4><p>We&#39;ll use a <strong>dictionary</strong> to store these groups. The key will be a tuple representing the frequency of each character in a word, and the value will be a list of words that share this frequency.</p><h4>Why Use a Tuple as the Key?</h4><p>Python dictionaries require their keys to be <strong>immutable</strong>. Since lists are mutable, we can&#39;t use a list as a key. However, tuples are immutable, so we can use a tuple of character counts as our dictionary key.</p><h4>Step-by-Step Breakdown of the Solution</h4><p>Let&#39;s go step by step and explain the logic:</p><p>1. <strong>Initialize a Dictionary:</strong> We&#39;ll use a defaultdict from the collections module, which allows us to automatically initialize values as empty lists.<br> <br>2. <strong>Iterate Over the Words:</strong> For each word in the input list, we will:<br>Create a list of size 26 (one for each letter in the English alphabet) initialized to zeros. This list will store the frequency of each character in the word.<br>For each character in the word, we&#39;ll increase the count at the corresponding index. We can calculate the index using `ord(char) - ord(&#39;a&#39;)`, which gives us the position of the character in the alphabet (for example, &#39;a&#39; is 0, &#39;b&#39; is 1, etc.).<br> <br>3. <strong>Use the Count Tuple as the Key:</strong> Convert this list of character counts into a tuple and use it as the key in the dictionary.<br> <br>4. <strong>Group the Words:</strong> Append the word to the list corresponding to the tuple key.</p><p>5.<strong> Return the Result</strong>: Finally, we&#39;ll return the values of the dictionary, which will be lists of grouped anagrams.</p><p><strong>Python Code Implementation</strong></p><pre>python<br>from collections import defaultdict<br>def group_anagrams(strs):<br>    # Step 1: Initialize a defaultdict with lists as the default value type<br>    anagram = defaultdict(list)<br>    # Step 2: Loop through each word in the input list<br>    for s in strs:<br>        # Step 3: Create a count list of size 26 for each word<br>        count = [0] * 26<br>        for char in s:<br>            # Step 4: Increment the count for each character<br>            count[ord(char) - ord(&#39;a&#39;)] += 1<br>        <br>        # Step 5: Convert the count list to a tuple and use it as the dictionary key<br>        anagram[tuple(count)].append(s)<br>    # Step 6: Return the grouped anagrams<br>    return list(anagram.values())<br></pre><h4>Explanation of the Code</h4><ul><li><strong>defaultdict(list)</strong>: This initializes a dictionary where each key points to a list by default.</li><li><strong>ord(char) - ord(&#39;a&#39;):</strong> This gives us the position of a character in the alphabet. For example, &#39;a&#39; is 0, &#39;b&#39; is 1, etc.</li><li><strong>tuple(count):</strong> Since lists are mutable, we convert the count list into a tuple so that it can be used as a dictionary key.</li><li><strong>anagram[tuple(count)].append(s)</strong>: For each word, we append it to the list corresponding to its character count tuple.</li></ul><h4>Example Walkthrough</h4><p>Let&#39;s break down the input `[&quot;eat&quot;, &quot;tea&quot;, &quot;tan&quot;, &quot;ate&quot;, &quot;nat&quot;, &quot;bat&quot;]`:</p><p>1. For &quot;eat&quot;:<br> - The count array becomes `[1, 0, 0, ..., 1, 0, 0]` (1 &#39;e&#39;, 1 &#39;a&#39;, 1 &#39;t&#39;).<br> - This gets stored as the key `(1, 0, 0, ..., 1, 0, 0)`, and &quot;eat&quot; is added to the list for this key.<br> <br>2. For &quot;tea&quot;:<br> - The count array is the same as &quot;eat&quot;.<br> - &quot;tea&quot; is added to the list for the same key.</p><p>3. For &quot;tan&quot;:<br> - The count array becomes `[1, 0, 0, ..., 0, 1, 1]` (1 &#39;t&#39;, 1 &#39;a&#39;, 1 &#39;n&#39;).<br> - A new key is created for this count, and &quot;tan&quot; is added.</p><p>This process continues for the rest of the words.</p><h4>Time Complexity</h4><ul><li><strong>Building the Count Array</strong>: For each word, we iterate through all its characters, which takes O(n) time, where n is the length of the word.</li><li><strong>Inserting into the Dictionary</strong>: This is done in constant time, O(1).<br>- The overall time complexity is O(N * K), where N is the number of words and K is the maximum length of a word.</li></ul><h4>Conclusion</h4><p>The Group Anagrams problem is a great exercise in using dictionaries and understanding tuples in Python. By recognizing that anagrams have the same character frequencies, we can efficiently group words using a tuple of character counts as the key.</p><p>This problem not only helps you practice dictionary manipulation but also gives insight into how immutable types like tuples can be effectively used as keys in dictionaries.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94c29f0243b3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Contains Duplicate Leetcode 217]]></title>
            <link>https://medium.com/@ishanupadhyay412/contains-duplicate-leetcode-217-77110f717657?source=rss-e4071348b5c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/77110f717657</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[hashing]]></category>
            <dc:creator><![CDATA[ISHAN UPADHYAY]]></dc:creator>
            <pubDate>Thu, 05 Sep 2024 07:58:52 GMT</pubDate>
            <atom:updated>2024-09-05T07:58:52.053Z</atom:updated>
            <content:encoded><![CDATA[<p>Given an integer array nums, return true if any value appears <strong>at least twice</strong> in the array, and return false if every element is distinct.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*jYDNAY6RGiJa_k4mrAtx2w.png" /></figure><p>Duplicate detection in arrays is a common problem in coding interviews and algorithm practice. In this blog, I’ll walk you through several approaches, ranging from naive to more efficient ones. We’ll analyze the time and space complexities of each method to help you understand their trade-offs.</p><p>1. Naive Approach: Nested Loops</p><p>The most basic approach is to use two nested loops to compare every element with every other element. If we find two equal elements, we return `true`. If no duplicates are found after all comparisons, we return `false`.</p><pre><br>def contains_duplicate_naive(arr):<br> for i in range(len(arr)):<br> for j in range(i + 1, len(arr)):<br> if arr[i] == arr[j]:<br> return True<br> return False</pre><p><strong>Time Complexity: O(n²) <br>Space Complexity: O(1)</strong></p><p>While this method works, it is inefficient due to the nested loops that result in O(n²) time complexity. This would become slow for large arrays.</p><p><strong>2. Sorting the Array</strong></p><p>The next step towards efficiency is sorting the array. After sorting, duplicates will appear next to each other. We can then iterate through the sorted array once, checking if any adjacent elements are equal.</p><pre><br>def contains_duplicate_sorted(arr):<br> arr.sort() # Sort the array<br> for i in range(1, len(arr)):<br> if arr[i] == arr[i — 1]:<br> return True<br> return False</pre><p><strong>Time Complexity: O(n log n) (due to sorting) <br>Space Complexity: O(1) or O(n) depending on the sorting algorithm used</strong></p><p>This approach improves time complexity compared to the naive method but still isn’t the most optimal due to the sorting step.</p><p><strong>3. Using a HashSet (Hash Table)</strong></p><p>The most common approach for checking duplicates involves using a hash set (or hash table). The idea is to iterate through the array and store elements in the set. If we encounter an element that is already in the set, we know that there is a duplicate.</p><pre><br>def contains_duplicate_set(arr):<br> seen = set()<br> for num in arr:<br> if num in seen:<br> return True<br> seen.add(num)<br> return False</pre><p><strong>Time Complexity: O(n) <br>Space Complexity: O(n)</strong></p><p>This approach is optimal in terms of time complexity as we only need to traverse the array once, making it O(n). The space complexity is also O(n) due to the extra space required for the set.</p><p><strong>4. Comparing Length of Array and Set</strong></p><p>An even shorter solution leverages Python’s `set()` data structure. If an array contains duplicates, the length of the set (which holds only unique elements) will be less than the length of the original array. This allows us to check for duplicates in a single line of code.</p><pre><br>def contains_duplicate_len(arr):<br> return len(arr) != len(set(arr))</pre><p><strong>Time Complexity: O(n) <br>Space Complexity: O(n)</strong></p><p>This is a clean, concise approach, and while it achieves the same time complexity as the previous method, it may be slightly slower in practice due to the overhead of creating the set. However, it’s very readable.</p><p><strong>Which Approach is Best?</strong></p><ul><li>The naive Approach (O(n²)) is generally not suitable for large arrays.</li><li>The sorting Approach (O(n log n)) is a reasonable solution if we don’t have extra space constraints.</li><li>The HashSet Approach (O(n)) is the most efficient in terms of time and is preferred when space isn’t a concern.</li><li>Length Comparison with Set (O(n)) is concise and clean but not necessarily more performant than the hash set solution.</li></ul><h4>Conclusion</h4><p>Each solution has its trade-offs. For most practical purposes, using a hash set to track elements (Solution 3) is the best choice due to its O(n) time complexity and simple implementation. The `len()` and `set()` approach is an elegant one-liner but might not be the fastest when compared to the direct hash table approach. Happy coding!</p><p>This format should give a clear comparison between the different approaches while showcasing how to optimize performance step-by-step. Let me know if you’d like to refine any of the sections further!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77110f717657" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Semantic Versioning: A Complete Guide to Software Versioning Best Practices]]></title>
            <link>https://medium.com/@ishanupadhyay412/mastering-semantic-versioning-a-complete-guide-to-software-versioning-best-practices-67c0724f14ce?source=rss-e4071348b5c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/67c0724f14ce</guid>
            <category><![CDATA[semantic-versioning]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[version-control]]></category>
            <dc:creator><![CDATA[ISHAN UPADHYAY]]></dc:creator>
            <pubDate>Wed, 04 Sep 2024 07:27:40 GMT</pubDate>
            <atom:updated>2024-09-04T07:30:49.194Z</atom:updated>
            <content:encoded><![CDATA[<p>In the competitive landscape of software development, maintaining a clear and consistent versioning strategy is essential for developers and users alike. <strong>Semantic Versioning (SemVer)</strong> has become the go-to standard for managing software versioning, offering a predictable and transparent approach to releasing updates. Whether you’re managing an open-source project or an enterprise-level application, understanding and implementing Semantic Versioning can significantly enhance your software’s reliability and user satisfaction.</p><h4>What is Semantic Versioning?</h4><p><strong>Semantic Versioning</strong> is a structured versioning system that uses a three-part number format: MAJOR.MINOR.PATCH. This format provides a clear and intuitive way to communicate changes in your software:</p><ul><li><strong>MAJOR Version</strong>: Incremented for <strong>incompatible API changes</strong> that may break existing functionality.</li><li><strong>MINOR Version</strong>: Incremented when <strong>new features</strong> are added in a backward-compatible manner.</li><li><strong>PATCH Version</strong>: Incremented for <strong>backward-compatible bug fixes</strong> that do not affect existing features.</li></ul><p>For example, a version number like 2.1.5 indicates that the project is in its 2nd major iteration, has had one minor feature update since the last major version, and has been patched five times.</p><h4>Why is Semantic Versioning Important?</h4><p>Adopting <strong>Semantic Versioning</strong> is crucial for several reasons:</p><ol><li><strong>Predictability</strong>: Users can anticipate the impact of an update by simply looking at the version number, reducing the risk of unexpected breaking changes.</li><li><strong>Dependency Management</strong>: Developers can manage dependencies more effectively, knowing when a major version change may require code refactoring.</li><li><strong>Clear Communication</strong>: Semantic Versioning provides a common language for teams and users, ensuring everyone stays aligned on software changes.</li></ol><h4>How to Implement Semantic Versioning</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zAmBT8_joXabW6dtYsi6XQ.png" /></figure><p>Implementing <strong>Semantic Versioning</strong> in your project is straightforward, but it requires discipline and a thorough understanding of your software’s structure and dependencies. Here’s how you can get started:</p><h4>1. Start with 1.0.0</h4><p>Begin Semantic Versioning with 1.0.0 once your software is ready for public release. Versions below 1.0.0 are typically reserved for initial development phases and are considered unstable, with no guaranteed API stability.</p><h4>2. Increment the Version Numbers</h4><ul><li><strong>MAJOR Version</strong>: Increase this when you make incompatible API changes, such as removing or altering a function signature. <strong>Example</strong>: Moving from 1.0.0 to 2.0.0.</li><li><strong>MINOR Version</strong>: Increase this when you add new features or functionality in a backward-compatible manner. <strong>Example</strong>: Moving from 1.0.0 to 1.1.0.</li><li><strong>PATCH Version</strong>: Increase this for backward-compatible bug fixes that do not alter existing functionality. <strong>Example</strong>: Moving from 1.0.0 to 1.0.1.</li></ul><h4>3. Pre-Release Versions: Essential for Testing and Feedback</h4><p>Pre-release versions are an essential component of Semantic Versioning, allowing you to test new features and gather feedback before a full release. These versions are identified by appending a hyphen followed by identifiers such as alpha, beta, or rc (release candidate).</p><p><strong>Understanding Pre-Release Versions</strong></p><p>A pre-release version is a development snapshot that is not yet ready for production but is suitable for testing or previewing new features. This allows teams to identify bugs and gather user feedback, making necessary adjustments before the official release.</p><p><strong>Formatting Pre-Release Versions</strong></p><p>Pre-release versions use a hyphen and a series of dot-separated identifiers appended to the regular version number:</p><ul><li><strong>Alphanumeric identifiers</strong>: Common identifiers include alpha, beta, rc.</li><li><strong>Sequential numbers</strong>: Used to denote iterations of the pre-release (e.g., alpha.1, beta.2).</li></ul><p><strong>Examples</strong>:</p><ul><li><strong>1.0.0-alpha</strong>: The first alpha release, indicating an early stage of development.</li><li><strong>1.0.0-beta.1</strong>: The first beta release, is usually more stable but still likely to contain bugs.</li><li><strong>1.0.0-rc.1</strong>: The first release candidate, signaling that the software is nearing a stable release.</li></ul><p><strong>When to Use Pre-Release Versions</strong></p><ul><li><strong>Feature Testing</strong>: Introduce new features with versions 1.2.0-alpha to gather early feedback before including them in a stable release.</li><li><strong>Release Candidates</strong>: Before a major release, use 2.0.0-rc.1 to signal that this version is ready for final testing.</li><li><strong>Bug Fixes in Pre-Releases</strong>: Update the version from 1.2.0-beta.1 to 1.2.0-beta.2 after addressing bugs identified during testing.</li></ul><h4>4. Build Metadata for Advanced Versioning</h4><p>For projects that require additional specificity, build metadata can be appended after a plus sign (e.g., 1.0.0+20130313144700). While this metadata is useful for identifying specific builds, it doesn’t affect version precedence.</p><h4>Common Pitfalls to Avoid in Semantic Versioning</h4><ol><li><strong>Skipping Version Numbers</strong>: Avoid skipping version numbers. Even small changes require the appropriate version number increment.</li><li><strong>Incorrect Version Bumps</strong>: Ensure that major, minor, and patch versions are updated according to the nature of the changes, maintaining consistency.</li><li><strong>Ignoring Dependencies</strong>: Always consider your software’s dependencies when updating version numbers. A major version change in a library may require a corresponding update in your software.</li></ol><h4>Conclusion</h4><p><strong>Semantic Versioning</strong> is not just a versioning strategy — it’s a vital communication tool in software development. By adhering to its principles, you can ensure that your software evolves predictably, enhancing both development efficiency and user experience.</p><p>Pre-release versions add an extra layer of control, allowing for thorough testing and refinement before a stable release. They are indispensable for catching issues early and ensuring that the final product is both reliable and feature-complete.</p><p>Whether you’re managing a new project or maintaining a mature one, adopting <strong>Semantic Versioning</strong> is a best practice that will pay off in the long run. It promotes transparency, reliability, and clarity throughout the software development lifecycle, leading to better, more maintainable software.</p><p>So before your next software release, take a moment to consider your versioning strategy. Using Semantic Versioning effectively will not only streamline your development process but also build trust with your users.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67c0724f14ce" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>