<?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: Bollam Shiva Shankara Varapras</title>
    <description>The latest articles on DEV Community by Bollam Shiva Shankara Varapras (@shivabollam07).</description>
    <link>https://dev.to/shivabollam07</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%2F1139481%2F4d3ea27d-c44c-466d-848b-bc780fb1b3b4.jpg</url>
      <title>DEV Community: Bollam Shiva Shankara Varapras</title>
      <link>https://dev.to/shivabollam07</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shivabollam07"/>
    <language>en</language>
    <item>
      <title>Understanding the OSI Model: A Step-by-Step Breakdown</title>
      <dc:creator>Bollam Shiva Shankara Varapras</dc:creator>
      <pubDate>Mon, 21 Oct 2024 03:12:59 +0000</pubDate>
      <link>https://dev.to/shivabollam07/understanding-the-osi-model-a-step-by-step-breakdown-3np1</link>
      <guid>https://dev.to/shivabollam07/understanding-the-osi-model-a-step-by-step-breakdown-3np1</guid>
      <description>&lt;p&gt;The OSI (Open Systems Interconnection) model is a conceptual framework that helps us understand how data moves across a network. It divides network communication into seven layers, each responsible for specific tasks. This blog will break down these layers, step-by-step, using an easy-to-understand example: visiting a website from your browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The 7 Layers of the OSI Model&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1. Application Layer (Layer 7)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;What It Does:&lt;/em&gt;&lt;/strong&gt; The Application layer is where user interaction happens. This is the layer closest to the end-user and handles software applications like web browsers (Chrome, Firefox).&lt;br&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Example:&lt;/em&gt;&lt;/strong&gt; When you type a URL (e.g., &lt;a href="http://www.example.com" rel="noopener noreferrer"&gt;www.example.com&lt;/a&gt;) and hit enter, your browser sends an HTTP/HTTPS request to the web server hosting the website. This layer doesn’t handle the data transfer but makes sure that web applications like browsers can communicate over the network.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;2. Presentation Layer (Layer 6)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;What It Does:&lt;/em&gt;&lt;/strong&gt; The Presentation layer ensures that data is in the correct format for the application. It manages encryption, decryption, compression, and translation of data.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Example:&lt;/em&gt;&lt;/strong&gt; If you’re visiting a secure website (using HTTPS), this layer ensures the data is encrypted with SSL/TLS so your browser can securely exchange information with the web server.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;3. Session Layer (Layer 5)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;What It Does:&lt;/em&gt;&lt;/strong&gt; This layer manages sessions between devices. It establishes, maintains, and terminates communication sessions between applications.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Example:&lt;/em&gt;&lt;/strong&gt; Once you start browsing a website, the Session layer keeps your session active as you navigate through different pages, ensuring a continuous connection between your browser and the server.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;4. Transport Layer (Layer 4)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;What It Does:&lt;/em&gt;&lt;/strong&gt; The Transport layer is responsible for reliable data transmission. It manages data flow and error-checking using protocols like TCP (Transmission Control Protocol) or UDP (User Datagram Protocol).&lt;br&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Example:&lt;/em&gt;&lt;/strong&gt; When you load a webpage, &lt;strong&gt;TCP&lt;/strong&gt; ensures that the data (web content) is sent reliably. It establishes a &lt;strong&gt;three-way handshake&lt;/strong&gt; between your browser and the web server to confirm a stable connection.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;5. Network Layer (Layer 3)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;What It Does:&lt;/em&gt;&lt;/strong&gt; The Network layer is responsible for routing data between different networks. It uses &lt;strong&gt;IP addresses&lt;/strong&gt; to ensure data packets are sent to the correct destination.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Example:&lt;/em&gt;&lt;/strong&gt; Your webpage request is assigned a source IP address (your device) and a destination IP address (the web server). Routers help direct the data packets across different networks until they reach the right destination.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;6. Data Link Layer (Layer 2)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;What It Does:&lt;/em&gt;&lt;/strong&gt; The Data Link layer manages communication between devices on the same network and ensures that data is properly packaged into frames. It also uses &lt;strong&gt;MAC addresses&lt;/strong&gt; to identify devices within the network.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Example:&lt;/em&gt;&lt;/strong&gt; When your data is sent within your home Wi-Fi network, the Data Link layer ensures that the frames of data move between your laptop and the router using MAC addresses.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;7. Physical Layer (Layer 1)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;What It Does:&lt;/em&gt;&lt;/strong&gt; The Physical layer is responsible for the actual physical connection and the transmission of raw data (bits) over a medium such as cables, fiber optics, or wireless signals.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Example:&lt;/em&gt;&lt;/strong&gt; The binary data (1s and 0s) representing your webpage request is transmitted from your device to your router via &lt;strong&gt;Wi-Fi signals&lt;/strong&gt; or &lt;strong&gt;Ethernet cables&lt;/strong&gt;. The router then sends the data out to the internet over physical mediums like fiber optic cables.&lt;/p&gt;

</description>
      <category>networking</category>
      <category>devops</category>
      <category>kubernetes</category>
      <category>programming</category>
    </item>
    <item>
      <title>.js vs. .jsx: Should You Write Your React Code in .jsx?</title>
      <dc:creator>Bollam Shiva Shankara Varapras</dc:creator>
      <pubDate>Sun, 01 Sep 2024 04:43:12 +0000</pubDate>
      <link>https://dev.to/shivabollam07/js-vs-jsx-should-you-write-your-react-code-in-jsx-3mp9</link>
      <guid>https://dev.to/shivabollam07/js-vs-jsx-should-you-write-your-react-code-in-jsx-3mp9</guid>
      <description>&lt;p&gt;When working with React, one of the decisions you'll face is whether to write your React components in .js or .jsx files. This choice can impact your project's clarity and maintainability. In this blog post, we'll explore the differences between .js and .jsx files and help you decide which is right for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Are .js and .jsx Files?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;.js Files&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Definition: .js files are the standard extension for JavaScript files.&lt;/li&gt;
&lt;li&gt;Usage: You can write React code, including JSX syntax, in .js files. However, this requires proper configuration of your build tools to handle JSX.&lt;/li&gt;
&lt;li&gt;Configuration: Make sure your build system (e.g., Babel) is set up to transpile JSX code into standard JavaScript.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;.jsx Files&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Definition: .jsx is a convention that indicates the file contains JSX syntax.&lt;/li&gt;
&lt;li&gt;Usage: Using .jsx makes it explicit that the file includes JSX, which can improve readability and understanding of your code.&lt;/li&gt;
&lt;li&gt;Configuration: .jsx files also require appropriate build tool configurations, similar to .js files, to transpile JSX.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Pros and Cons of Using .jsx
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Clarity: By using .jsx, you clearly indicate that the file contains JSX, which can make your codebase easier to navigate and understand.&lt;/li&gt;
&lt;li&gt;Convention: Many teams and projects use .jsx to follow established conventions, making it easier for new developers to get up to speed.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Additional Extension: You’ll need to ensure your development tools (like ESLint, Prettier) are configured to handle .jsx files.&lt;/li&gt;
&lt;li&gt;Inconsistency: If your project or team uses .js for everything, introducing .jsx might create inconsistency.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Making Your Decision
&lt;/h2&gt;

&lt;p&gt;Whether to use .js or .jsx comes down to personal or team preference and the conventions of your project. If clarity and following conventions are important to you, .jsx might be the way to go. On the other hand, if you prefer simplicity and consistency, sticking with .js should work just fine as long as your build tools are properly configured.&lt;/p&gt;

&lt;p&gt;In the end, both file extensions serve the same purpose, and with the right configuration, you can use either without issues. Choose the one that best fits your project’s needs and your team’s workflow.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>1669 Merge in Between Linked Lists - Leetcode</title>
      <dc:creator>Bollam Shiva Shankara Varapras</dc:creator>
      <pubDate>Sat, 20 Jul 2024 04:22:23 +0000</pubDate>
      <link>https://dev.to/shivabollam07/1669-merge-in-between-linked-lists-leetcode-144c</link>
      <guid>https://dev.to/shivabollam07/1669-merge-in-between-linked-lists-leetcode-144c</guid>
      <description>&lt;h2&gt;
  
  
  Approach
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Find the node at index a - 1 and b&lt;/li&gt;
&lt;li&gt;Set the next of the node at index&lt;/li&gt;
&lt;li&gt;Find the last node of list2&lt;/li&gt;
&lt;li&gt;Set the next of the last node of list2 to the next of the node at index b&lt;/li&gt;
&lt;li&gt;Return the head of the list&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Complexity
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Time complexity: O(n)
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Space complexity: O(1)
&lt;/h3&gt;

&lt;h2&gt;
  
  
  Java Code
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution {
    public ListNode mergeInBetween(ListNode list1, int a, int b, ListNode list2) {
        ListNode start = list1;
        ListNode end = list1;
        for (int i = 0; i &amp;lt; a - 1; i++) {
            start = start.next;
        }
        for (int i = 0; i &amp;lt; b; i++) {
            end = end.next;
        }
        start.next = list2;
        while (list2.next != null) {
            list2 = list2.next;
        }
        list2.next = end.next;
        return list1; 
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>programming</category>
      <category>computerscience</category>
      <category>coding</category>
      <category>leetcode</category>
    </item>
    <item>
      <title>Solving "All Nodes Distance K in Binary Tree" Leet code Question</title>
      <dc:creator>Bollam Shiva Shankara Varapras</dc:creator>
      <pubDate>Sat, 16 Sep 2023 06:00:00 +0000</pubDate>
      <link>https://dev.to/shivabollam07/solving-all-nodes-distance-k-in-binary-tree-leet-code-question-30if</link>
      <guid>https://dev.to/shivabollam07/solving-all-nodes-distance-k-in-binary-tree-leet-code-question-30if</guid>
      <description>&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;p&gt;Given a binary tree, you are given a target node &lt;code&gt;target&lt;/code&gt; and an integer &lt;code&gt;k&lt;/code&gt;. Return a list of all the values that are at a distance &lt;code&gt;k&lt;/code&gt; from the target node in the tree.&lt;/p&gt;

&lt;h2&gt;
  
  
  Approach
&lt;/h2&gt;

&lt;p&gt;The idea to solve this problem is to perform a depth-first search (DFS) traversal of the binary tree to find nodes at a distance &lt;code&gt;k&lt;/code&gt; from the target node. We'll use a few helper functions to achieve this.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;UpdateParent Function&lt;/strong&gt;: We'll start by creating a mapping of each node to its parent node. This will help us navigate the tree later.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Traversal Function&lt;/strong&gt;: In this function, we'll perform the DFS traversal. When we reach a node at a distance &lt;code&gt;k&lt;/code&gt; from the target node, we add its value to the result list. We also maintain a &lt;code&gt;HashSet&lt;/code&gt; to keep track of visited nodes to avoid revisiting them. The recursion continues until we either find nodes at distance &lt;code&gt;k&lt;/code&gt; or reach the end of the tree.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally, in the &lt;code&gt;distanceK&lt;/code&gt; function, we initialize the necessary data structures and call the &lt;code&gt;UpdateParent&lt;/code&gt; function to create the mapping of nodes to their parents. Then, we call the &lt;code&gt;Traversal&lt;/code&gt; function to find nodes at distance &lt;code&gt;k&lt;/code&gt; from the target node and add their values to the result list.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Complexity Analysis
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Time Complexity: The DFS traversal of the binary tree takes O(n) time, where n is the number of nodes in the tree.&lt;/li&gt;
&lt;li&gt;Space Complexity: The space complexity is O(n) due to the space used by the HashMap, HashSet, and the recursion stack.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Code :
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
class Solution {

    public void UpdateParent(TreeNode Parent, TreeNode Current, HashMap&amp;lt;TreeNode, TreeNode&amp;gt; map) {
        if (Current == null) {
            return;
        }
        map.put(Current, Parent);

        UpdateParent(Current, Current.left, map);
        UpdateParent(Current, Current.right, map);
    }

    public void Traversal(int distance, TreeNode node, HashMap&amp;lt;TreeNode, TreeNode&amp;gt; map, List&amp;lt;Integer&amp;gt; list,HashSet&amp;lt;TreeNode&amp;gt; set) {
        if (node == null) {
            return;
        }
        if (set.contains(node)) {
            return;
        }
        set.add(node);

        if (distance == 0) {
            list.add(node.val);
            return;
        }
        Traversal(distance - 1, node.left, map, list, set);
        Traversal(distance - 1, node.right, map, list, set);
        Traversal(distance - 1, map.get(node), map, list, set);

    }

    public List&amp;lt;Integer&amp;gt; distanceK(TreeNode root, TreeNode target, int k) {
        HashMap&amp;lt;TreeNode, TreeNode&amp;gt; map = new HashMap&amp;lt;&amp;gt;();
        HashSet&amp;lt;TreeNode&amp;gt; set = new HashSet&amp;lt;&amp;gt;();
        List&amp;lt;Integer&amp;gt; list = new ArrayList&amp;lt;&amp;gt;();
        UpdateParent(null, root, map);
        Traversal(k, target, map, list, set);
        return list;
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>beginners</category>
      <category>java</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Solving "Diameter of Binary Tree" Leet code Question</title>
      <dc:creator>Bollam Shiva Shankara Varapras</dc:creator>
      <pubDate>Thu, 14 Sep 2023 09:06:53 +0000</pubDate>
      <link>https://dev.to/shivabollam07/solving-diameter-of-binary-tree-leet-code-question-264l</link>
      <guid>https://dev.to/shivabollam07/solving-diameter-of-binary-tree-leet-code-question-264l</guid>
      <description>&lt;h2&gt;
  
  
  Intuition
&lt;/h2&gt;

&lt;p&gt;We want to find the diameter of a &lt;code&gt;binary tree&lt;/code&gt;, which is the length of the longest &lt;code&gt;path&lt;/code&gt; between any two nodes. This path may or may not pass through the &lt;code&gt;root&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Approach
&lt;/h2&gt;

&lt;p&gt;We perform a depth-first traversal of the tree and calculate the height of each subtree. While calculating the height of each node, we also update the diameter if a longer path is found. The final result will be stored in the &lt;code&gt;diameter&lt;/code&gt; variable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Time complexity&lt;/strong&gt;&lt;br&gt;
O(n) - We visit each node once.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Space complexity&lt;/strong&gt;&lt;br&gt;
O(h) - Recursive call stack space, where h is the height of the tree.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {

    int diameter = 0;

    public int diameterOfBinaryTree(TreeNode root) {
        height(root);
        return diameter;
    }

    public int height(TreeNode node){

        if(node == null) {
            return 0;
        }

        int lh = height(node.left);
        int rh = height(node.right);
        diameter = Math.max(diameter,lh+rh);

        return 1 + Math.max(lh,rh);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Happy coding,&lt;br&gt;
shiva&lt;/p&gt;

</description>
      <category>java</category>
      <category>programming</category>
      <category>discuss</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Solving "Binary Tree Level Order Traversal" Leet code Question</title>
      <dc:creator>Bollam Shiva Shankara Varapras</dc:creator>
      <pubDate>Wed, 13 Sep 2023 07:06:45 +0000</pubDate>
      <link>https://dev.to/shivabollam07/solving-binary-tree-level-order-traversal-leet-code-question-1pgh</link>
      <guid>https://dev.to/shivabollam07/solving-binary-tree-level-order-traversal-leet-code-question-1pgh</guid>
      <description>&lt;h2&gt;
  
  
  Leet code Question no: 102
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Companies asked this Question:&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Company: no of times&lt;/em&gt;&lt;br&gt;
Amazon 2&lt;br&gt;
Bloomberg 11&lt;br&gt;
Uber 2&lt;br&gt;
Apple 2&lt;br&gt;
LinkedIn 25&lt;br&gt;
Microsoft 13&lt;br&gt;
Facebook 12&lt;br&gt;
Oracle 7&lt;br&gt;
Google 5&lt;br&gt;
ServiceNow 3&lt;br&gt;
Splunk 2&lt;br&gt;
Adobe 2&lt;br&gt;
Docusign 2&lt;br&gt;
Accolite 2&lt;br&gt;
TikTok 2&lt;/p&gt;

&lt;h2&gt;
  
  
  Intuition
&lt;/h2&gt;

&lt;p&gt;We aim to perform a level-order traversal of a binary tree, collecting nodes at each level into sublists.&lt;/p&gt;

&lt;h2&gt;
  
  
  Approach
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Utilize a queue for level-order traversal, initializing an empty list &lt;code&gt;WrapList&lt;/code&gt; to store results.&lt;/li&gt;
&lt;li&gt;While the queue is not empty, dequeue nodes, collect their values into sublists, and enqueue their children.&lt;/li&gt;
&lt;li&gt;Add sublists to &lt;code&gt;WrapList&lt;/code&gt; as levels are processed and return it as the result.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Complexity
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Time complexity: O(n) - We visit each node once during the traversal.&lt;/li&gt;
&lt;li&gt;Space complexity: O(n) - The space usage grows with the number of nodes due to the queue and the result list.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public List&amp;lt;List&amp;lt;Integer&amp;gt;&amp;gt; levelOrder(TreeNode root) {
        List&amp;lt;List&amp;lt;Integer&amp;gt;&amp;gt; WrapList = new LinkedList&amp;lt;&amp;gt;();

        if(root == null)
            return WrapList;

        Queue&amp;lt;TreeNode&amp;gt; queue =  new LinkedList&amp;lt;&amp;gt;();
        queue.offer(root);

        while(!queue.isEmpty()){
            int levelNum = queue.size();
            List&amp;lt;Integer&amp;gt; subList = new LinkedList&amp;lt;&amp;gt;();

            for(int i = 0 ;  i &amp;lt; levelNum ; i++){
                TreeNode node = queue.poll();
                subList.add(node.val);

                if(node.left != null) queue.offer(node.left);
                if(node.right != null) queue.offer(node.right);
            }

            WrapList.add(subList);
        }

        return WrapList;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Happy coding,&lt;br&gt;
shiva&lt;/p&gt;

</description>
      <category>java</category>
      <category>programming</category>
      <category>discuss</category>
      <category>coding</category>
    </item>
    <item>
      <title>Solving "Move Zeroes" Leet code Question.</title>
      <dc:creator>Bollam Shiva Shankara Varapras</dc:creator>
      <pubDate>Tue, 12 Sep 2023 02:11:33 +0000</pubDate>
      <link>https://dev.to/shivabollam07/solving-move-zeroes-leet-code-question-8k2</link>
      <guid>https://dev.to/shivabollam07/solving-move-zeroes-leet-code-question-8k2</guid>
      <description>&lt;h2&gt;
  
  
  283. Move Zeroes
&lt;/h2&gt;

&lt;p&gt;Type: Easy&lt;br&gt;
Liked by 15.2K&lt;br&gt;
Disliked by 380.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Companies that asked this question&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Companies: No of times asked&lt;/em&gt;&lt;br&gt;
Yandex 8&lt;br&gt;
Apple 3&lt;br&gt;
Amazon 3&lt;br&gt;
Facebook 11&lt;br&gt;
Bloomberg 6&lt;br&gt;
Google 4&lt;br&gt;
Adobe 3&lt;br&gt;
Microsoft 2&lt;br&gt;
Uber 2&lt;br&gt;
Oracle 2&lt;br&gt;
Splunk 2&lt;br&gt;
Tesla 2&lt;br&gt;
tcs 6&lt;br&gt;
Expedia 4&lt;br&gt;
VMware 3&lt;br&gt;
Goldman Sachs 3&lt;br&gt;
ByteDance 3&lt;br&gt;
JPMorgan 3&lt;br&gt;
TikTok 3&lt;br&gt;
LinkedIn 2&lt;br&gt;
Yahoo 2&lt;br&gt;
IBM 2&lt;br&gt;
Morgan Stanley 2&lt;br&gt;
ServiceNow 2&lt;br&gt;
Salesforce 2&lt;br&gt;
Zoho 2&lt;br&gt;
Infosys 2&lt;br&gt;
Nvidia 2&lt;br&gt;
Samsung 2&lt;br&gt;
Wix 1&lt;/p&gt;

&lt;p&gt;Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements.&lt;/p&gt;

&lt;p&gt;Note that you must do this in-place without making a copy of the array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1:&lt;/strong&gt;&lt;br&gt;
Input: nums = &lt;code&gt;[0,1,0,3,12]&lt;/code&gt;&lt;br&gt;
Output: &lt;code&gt;[1,3,12,0,0]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 2:&lt;/strong&gt;&lt;br&gt;
Input: nums = &lt;code&gt;[0]&lt;/code&gt;&lt;br&gt;
Output: &lt;code&gt;[0]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Constraints:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;1 &amp;lt;= nums.length &amp;lt;= 104&lt;/code&gt;&lt;br&gt;
&lt;code&gt;-231 &amp;lt;= nums[i] &amp;lt;= 231 - 1&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Intuition
&lt;/h1&gt;

&lt;p&gt;We want to move all the &lt;code&gt;zeros&lt;/code&gt; to the end of the &lt;code&gt;array&lt;/code&gt; while keeping the &lt;code&gt;non-zero&lt;/code&gt; elements in their relative order.&lt;/p&gt;

&lt;h1&gt;
  
  
  Approach
&lt;/h1&gt;

&lt;p&gt;We maintain &lt;code&gt;two pointers: i&lt;/code&gt; to iterate through the &lt;code&gt;array&lt;/code&gt; and &lt;code&gt;nonZeroIndex&lt;/code&gt; to keep track of the &lt;code&gt;position&lt;/code&gt; where we should insert non-zero elements. When we encounter a non-zero element, we &lt;code&gt;swap&lt;/code&gt; it with the element at nonZeroIndex and then increment nonZeroIndex.&lt;/p&gt;

&lt;h1&gt;
  
  
  Complexity
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Time complexity:&lt;/strong&gt;&lt;br&gt;
The code iterates through the array once, so the time complexity is   &lt;code&gt;O(n)&lt;/code&gt;, where &lt;code&gt;n&lt;/code&gt; is the length of the array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Space complexity:&lt;/strong&gt;&lt;br&gt;
The code uses a constant amount of extra space, so the space complexity is &lt;code&gt;O(1)&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Code
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution {
    public void moveZeroes(int[] nums) {
        int nonZeroIndex = 0; 
        for (int i = 0; i &amp;lt; nums.length; i++) {
            if (nums[i] != 0) {
                int temp = nums[i];
                nums[i] = nums[nonZeroIndex];
                nums[nonZeroIndex] = temp;
                nonZeroIndex++; 
            }
        }
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Happy coding,&lt;br&gt;
shiva&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>programming</category>
      <category>java</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Solving "Climbing Stairs" Leet code Problem</title>
      <dc:creator>Bollam Shiva Shankara Varapras</dc:creator>
      <pubDate>Sun, 10 Sep 2023 16:59:10 +0000</pubDate>
      <link>https://dev.to/shivabollam07/solving-climbing-stairs-leet-code-problem-46kf</link>
      <guid>https://dev.to/shivabollam07/solving-climbing-stairs-leet-code-problem-46kf</guid>
      <description>&lt;h2&gt;
  
  
  Question:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;70. Climbing Stairs&lt;/strong&gt;&lt;br&gt;
Type: Easy&lt;br&gt;
Liked by 19.8K&lt;br&gt;
Disliked by 656.&lt;br&gt;
Companies that asked this question&lt;br&gt;
Companies: No of times asked&lt;br&gt;
Amazon 3&lt;br&gt;
Yahoo 2&lt;br&gt;
Adobe 11&lt;br&gt;
Google 5&lt;br&gt;
Apple 5&lt;br&gt;
Bloomberg 3&lt;br&gt;
Microsoft 3&lt;br&gt;
Uber 2&lt;br&gt;
Nagarro 2&lt;br&gt;
Expedia 12&lt;br&gt;
Oracle 4&lt;br&gt;
Goldman Sachs 3&lt;br&gt;
Facebook 2&lt;br&gt;
Intel 2&lt;br&gt;
Visa 2&lt;br&gt;
Optum 2&lt;br&gt;
Swiggy 2&lt;/p&gt;

&lt;p&gt;You are climbing a staircase. It takes n steps to reach the top.&lt;/p&gt;

&lt;p&gt;Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1:&lt;/strong&gt;&lt;br&gt;
Input: n =&lt;code&gt;2&lt;/code&gt;&lt;br&gt;
Output: &lt;code&gt;2&lt;/code&gt;&lt;br&gt;
Explanation: &lt;br&gt;
`There are two ways to climb to the top.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;1 step + 1 step&lt;/li&gt;
&lt;li&gt;2 steps`&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Example 2:&lt;/strong&gt;&lt;br&gt;
Input: n = &lt;code&gt;3&lt;/code&gt;&lt;br&gt;
Output: &lt;code&gt;3&lt;/code&gt;&lt;br&gt;
Explanation: &lt;br&gt;
`There are three ways to climb to the top.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;1 step + 1 step + 1 step&lt;/li&gt;
&lt;li&gt;1 step + 2 steps&lt;/li&gt;
&lt;li&gt;2 steps + 1 step`&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Constraints:&lt;br&gt;
&lt;code&gt;1 &amp;lt;= n &amp;lt;= 45&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Intuition:
&lt;/h1&gt;

&lt;p&gt;The problem is about finding the number of ways to climb a staircase when you can take either 1 step or 2 steps at a time. To solve it, you can use dynamic programming.&lt;/p&gt;

&lt;h1&gt;
  
  
  Approach:
&lt;/h1&gt;

&lt;p&gt;Create an array to store the number of ways to reach each step.&lt;br&gt;
Initialize the first two elements of the array (representing the first and second steps).&lt;br&gt;
Use a loop to calculate the number of ways to reach each subsequent step.&lt;br&gt;
Return the number of ways to reach the final step.&lt;/p&gt;

&lt;h1&gt;
  
  
  Complexity:
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Time Complexity&lt;/strong&gt;: O(n)&lt;br&gt;
&lt;strong&gt;Space Complexity&lt;/strong&gt;: O(n)&lt;/p&gt;

&lt;h1&gt;
  
  
  Code
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution {
    public int climbStairs(int n) {
        int[] arr = new int[n+1];

        if(n == 1){
            return 1;
        }
        else{
            arr[1] = 1;
            arr[2] = 2;
            for(int i = 3 ; i &amp;lt;=n ; i++){
                arr[i] = arr[i-1] + arr[i-2];
            }
        }
       return arr[n];
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Happy coding,&lt;br&gt;
shiva&lt;/p&gt;

</description>
      <category>java</category>
      <category>programming</category>
      <category>coding</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Solving the "Container With Most Water" Problem on Leet Code</title>
      <dc:creator>Bollam Shiva Shankara Varapras</dc:creator>
      <pubDate>Sun, 10 Sep 2023 07:32:32 +0000</pubDate>
      <link>https://dev.to/shivabollam07/solving-the-container-with-most-water-problem-on-leet-code-51f5</link>
      <guid>https://dev.to/shivabollam07/solving-the-container-with-most-water-problem-on-leet-code-51f5</guid>
      <description>&lt;h2&gt;
  
  
  11. Container With Most Water
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Type :&lt;/strong&gt; Medium&lt;br&gt;
&lt;strong&gt;Liked by:&lt;/strong&gt; 26.5K&lt;br&gt;
&lt;strong&gt;Disliked by:&lt;/strong&gt; 1.4K&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Companies that asked this Question&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Companies : No of Times asked&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Microsoft 4&lt;br&gt;
Google 4&lt;br&gt;
Amazon 3&lt;br&gt;
Adobe 2&lt;br&gt;
Bloomberg 2&lt;br&gt;
Apple 9&lt;br&gt;
Facebook 4&lt;br&gt;
Uber 3&lt;br&gt;
Oracle 2&lt;br&gt;
TikTok 2&lt;br&gt;
Goldman Sachs 5&lt;br&gt;
Intel 4&lt;br&gt;
Swiggy 4&lt;br&gt;
ByteDance 3&lt;br&gt;
VMware 3&lt;br&gt;
Qualtrics 3&lt;br&gt;
Intuit 3&lt;br&gt;
Flipkart 2&lt;br&gt;
Zoho 2&lt;br&gt;
Samsung 2&lt;br&gt;
eBay 2&lt;br&gt;
Walmart Labs 2&lt;br&gt;
Yandex 2&lt;br&gt;
Yahoo 2&lt;br&gt;
Cisco 2&lt;br&gt;
tcs 2&lt;br&gt;
Tesla 2&lt;br&gt;
C3 IoT 2&lt;br&gt;
Arcesium 2&lt;br&gt;
DE Shaw 2&lt;br&gt;
JPMorgan 2&lt;br&gt;
Wix 1&lt;/p&gt;

&lt;p&gt;You are given an integer array &lt;code&gt;height&lt;/code&gt; of length &lt;code&gt;n&lt;/code&gt;. There are n vertical lines drawn such that the two &lt;code&gt;endpoints&lt;/code&gt; of the &lt;code&gt;ith&lt;/code&gt; line are &lt;code&gt;(i, 0)&lt;/code&gt; and &lt;code&gt;(i, height[i]).&lt;/code&gt;&lt;br&gt;
Find two lines that together with the x-axis form a container, such that the container contains the most water.&lt;br&gt;
Return the maximum amount of water a container can store.&lt;br&gt;
Notice that you may not slant the container.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 2:&lt;/strong&gt;&lt;br&gt;
Input: height = &lt;code&gt;[1,8,6,2,5,4,8,3,7]&lt;/code&gt;&lt;br&gt;
Output: &lt;code&gt;49&lt;/code&gt;&lt;br&gt;
Explanation: &lt;code&gt;The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 2:&lt;/strong&gt;&lt;br&gt;
Input: height = &lt;code&gt;[1,1]&lt;/code&gt;&lt;br&gt;
Output: &lt;code&gt;1&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Intuition:
&lt;/h2&gt;

&lt;p&gt;The code aims to find the maximum area between two lines in a histogram, where the lines represent the heights of bars.&lt;/p&gt;

&lt;h2&gt;
  
  
  Approach:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Initialize pointers at both ends of the histogram (LeftPointer at 0 and RightPointer at the last element).&lt;/li&gt;
&lt;li&gt;While the LeftPointer is less than the RightPointer:&lt;/li&gt;
&lt;li&gt;Calculate the area between the lines formed by the heights at LeftPointer and RightPointer.&lt;/li&gt;
&lt;li&gt;Update the MaximumArea if the current area is greater.&lt;/li&gt;
&lt;li&gt;Move the pointer that points to the shorter line inward (towards the other pointer).&lt;/li&gt;
&lt;li&gt;Repeat step 2 until the pointers meet.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Complexity:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Time complexity:&lt;/strong&gt; O(n) where n is the number of elements in the height array. We iterate through the array once.&lt;br&gt;
&lt;strong&gt;Space complexity:&lt;/strong&gt; O(1) because we use a constant amount of extra space regardless of the input size.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution {
    public int maxArea(int[] height) {
        int MaximumArea = 0;
        int LeftPointer = 0;
        int RightPointer = height.length - 1;

        while(LeftPointer &amp;lt; RightPointer){
            if(height[LeftPointer] &amp;lt; height[RightPointer]){
                MaximumArea = Math.max(MaximumArea , height[LeftPointer] *(RightPointer - LeftPointer));
                LeftPointer++;
            }
            else{
                MaximumArea = Math.max(MaximumArea ,height[RightPointer] *(RightPointer - LeftPointer));
                RightPointer--;
            }
        }

        return MaximumArea;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Happy coding,&lt;br&gt;
shiva&lt;/p&gt;

</description>
      <category>java</category>
      <category>programming</category>
      <category>coding</category>
      <category>developers</category>
    </item>
    <item>
      <title>Solving the "Trapping Rain Water" Problem on Leet Code</title>
      <dc:creator>Bollam Shiva Shankara Varapras</dc:creator>
      <pubDate>Sun, 10 Sep 2023 05:35:23 +0000</pubDate>
      <link>https://dev.to/shivabollam07/solving-the-trapping-rain-water-problem-on-leet-code-ham</link>
      <guid>https://dev.to/shivabollam07/solving-the-trapping-rain-water-problem-on-leet-code-ham</guid>
      <description>&lt;h2&gt;
  
  
  Question
&lt;/h2&gt;

&lt;h2&gt;
  
  
  42. Trapping Rain Water
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Type:&lt;/strong&gt; Hard&lt;br&gt;
&lt;strong&gt;Liked by:&lt;/strong&gt; 29K&lt;br&gt;
&lt;strong&gt;Disliked by:&lt;/strong&gt; 412&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Companies that asked this Question&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Companies: No of times Asked&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Amazon 14&lt;br&gt;
Bloomberg 5&lt;br&gt;
Adobe 4&lt;br&gt;
Apple 4&lt;br&gt;
Goldman Sachs 3&lt;br&gt;
Yandex 3&lt;br&gt;
EPAM Systems 2&lt;br&gt;
Microsoft 16&lt;br&gt;
Google 9&lt;br&gt;
Uber 4&lt;br&gt;
MakeMyTrip 3&lt;br&gt;
Facebook 2&lt;br&gt;
eBay 2&lt;br&gt;
Salesforce 2&lt;br&gt;
Intel 8&lt;br&gt;
Rubrik 8&lt;br&gt;
Qualtrics 7&lt;br&gt;
Tesla 6&lt;br&gt;
Oracle 5&lt;br&gt;
Citadel 5&lt;br&gt;
VMware 4&lt;br&gt;
C3 IoT 4&lt;br&gt;
Snapchat 3&lt;br&gt;
Lyft 3&lt;br&gt;
Visa 3&lt;br&gt;
PayPal 3&lt;br&gt;
ServiceNow 3&lt;br&gt;
Swiggy 3&lt;br&gt;
National Instruments 3&lt;br&gt;
Sapient 3&lt;br&gt;
Zoho 2&lt;br&gt;
Intuit 2&lt;br&gt;
Coupang 2&lt;br&gt;
Yahoo 2&lt;br&gt;
Expedia 2&lt;br&gt;
Twitch 2&lt;br&gt;
Morgan Stanley 2&lt;br&gt;
DE Shaw 2&lt;br&gt;
TikTok 2&lt;br&gt;
Navi 2&lt;br&gt;
Airbnb 1 &lt;br&gt;
Zenefits 1&lt;br&gt;
Twitter 1&lt;br&gt;
Wix 1&lt;/p&gt;

&lt;p&gt;Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fb5lho9om9ah85sozyxtw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fb5lho9om9ah85sozyxtw.png" alt="Rainwater Image" width="412" height="161"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1:&lt;/strong&gt;&lt;br&gt;
Input: height = &lt;code&gt;[0,1,0,2,1,0,1,3,2,1,2,1]&lt;/code&gt;&lt;br&gt;
Output: &lt;code&gt;6&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Explanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rainwater (blue section) are being trapped.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 2:&lt;/strong&gt;&lt;br&gt;
Input: height = &lt;code&gt;[4,2,0,3,2,5]&lt;/code&gt;&lt;br&gt;
Output: &lt;code&gt;9&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Constraints:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;n == height.length&lt;br&gt;
1 &amp;lt;= n &amp;lt;= 2 * 104&lt;br&gt;
0 &amp;lt;= height[i] &amp;lt;= 105&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Intuition:
&lt;/h2&gt;

&lt;p&gt;The goal is to calculate the total trapped water between bars with given heights. We achieve this by computing left and right boundaries for each bar and then calculating trapped water based on these boundaries.&lt;/p&gt;

&lt;h2&gt;
  
  
  Approach:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Initialize res to 0, lb (left boundaries), and rb (right boundaries) arrays.&lt;/li&gt;
&lt;li&gt;Calculate left boundaries (lb) and right boundaries (rb) for each bar in the input array.&lt;/li&gt;
&lt;li&gt;Iterate through the input array, calculating trapped water for each bar and accumulating it in res.&lt;/li&gt;
&lt;li&gt;Return res as the total trapped water.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Complexity:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Time complexity:&lt;/strong&gt; O(n) where n is the number of elements in the input array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Space complexity:&lt;/strong&gt; O(n) due to the lb and rb arrays used to store boundaries.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution {
    public int trap(int[] height) {
        int  res = 0;
        int[] lb = new int[height.length];
        int[] rb = new int[height.length];

        lb[0] = height[0];
        for(int i = 1 ; i &amp;lt; height.length -1 ;i++){
            lb[i] = Math.max(height[i],lb[i-1]);
        }

        rb[height.length - 1] = height[height.length - 1 ];
        for(int i = height.length - 2 ; i &amp;gt;= 0;i--){
            rb[i] = Math.max(height[i],rb[i+1]);
        }

        for(int i = 1 ; i &amp;lt; height.length -1 ; i++){
            int tw = Math.min(lb[i],rb[i]) - height[i];
            res = res + tw;
        }

        return res;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Happy coding,&lt;br&gt;
shiva&lt;/p&gt;

</description>
      <category>java</category>
      <category>coding</category>
      <category>programming</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Solving the "Letter Combinations of a Phone Number" Problem on Leet Code</title>
      <dc:creator>Bollam Shiva Shankara Varapras</dc:creator>
      <pubDate>Sat, 09 Sep 2023 18:02:22 +0000</pubDate>
      <link>https://dev.to/shivabollam07/solving-the-letter-combinations-of-a-phone-number-problem-on-leet-code-10g8</link>
      <guid>https://dev.to/shivabollam07/solving-the-letter-combinations-of-a-phone-number-problem-on-leet-code-10g8</guid>
      <description>&lt;h2&gt;
  
  
  17. Letter Combinations of a Phone Number
&lt;/h2&gt;

&lt;p&gt;Question type: Medium&lt;br&gt;
Liked by 17.1K&lt;br&gt;
Disliked by 896&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Companies that asked this Question&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Company : Noof Times&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Amazon 5&lt;br&gt;
Apple 4&lt;br&gt;
Microsoft 6&lt;br&gt;
Google 5&lt;br&gt;
Facebook 4&lt;br&gt;
Uber 4&lt;br&gt;
Bloomberg 3&lt;br&gt;
DE Shaw 3&lt;br&gt;
Adobe 2&lt;br&gt;
eBay 2&lt;br&gt;
Intuit 2&lt;br&gt;
Yahoo 2&lt;br&gt;
Twilio 2&lt;br&gt;
Oracle 8&lt;br&gt;
Twitter 5&lt;br&gt;
Goldman Sachs 5&lt;br&gt;
Epic Systems 4&lt;br&gt;
Swiggy 4&lt;br&gt;
VMware 3&lt;br&gt;
Nutanix 3&lt;br&gt;
Duolingo 3&lt;br&gt;
Snapchat 2&lt;br&gt;
LinkedIn 2&lt;br&gt;
Samsung 2&lt;br&gt;
Morgan Stanley 2&lt;br&gt;
Cisco 2&lt;br&gt;
Walmart Labs 2&lt;br&gt;
Twitch 2&lt;br&gt;
Tesla 2&lt;br&gt;
ServiceNow 2&lt;br&gt;
Capital One 2&lt;br&gt;
Dropbox 1&lt;/p&gt;

&lt;p&gt;Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order.&lt;/p&gt;

&lt;p&gt;A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fr0jgp1eo6xnp3z61f087.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fr0jgp1eo6xnp3z61f087.png" alt="Image 1" width="800" height="648"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1:&lt;/strong&gt;&lt;br&gt;
Input: digits = &lt;code&gt;"23"&lt;/code&gt;&lt;br&gt;
Output: &lt;code&gt;["ad","ae","af","bd","be","bf","cd","ce","cf"]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 2:&lt;/strong&gt;&lt;br&gt;
Input: digits = &lt;code&gt;""&lt;/code&gt;&lt;br&gt;
Output: &lt;code&gt;[]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 3:&lt;/strong&gt;&lt;br&gt;
Input: digits = &lt;code&gt;"2"&lt;/code&gt;&lt;br&gt;
Output: &lt;code&gt;["a","b","c"]&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Approach:
&lt;/h2&gt;

&lt;h2&gt;
  
  
  How it works:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mapping:&lt;/strong&gt; Imagine each digit (2 to 9) on your phone has some letters associated with it, just like the letters on a computer keyboard. This code stores those associations in a list called keypad.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Main Job:&lt;/strong&gt; The main job is done by the letterCombinations function. You give it a sequence of digits, and it gives you back a list of all possible words you can make.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Starting Point:&lt;/strong&gt; If you don't give it any digits (an empty sequence), it says, "I can't make any words with that," and it gives you an empty list.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Magic Helper:&lt;/strong&gt; Inside the letterCombinations function, there's a special helper called letterCombinationsRecursive. This helper does most of the work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Recursive Idea:&lt;/strong&gt; The magic happens here. The helper looks at each digit one by one. For each digit, it finds the letters associated with that digit from the keypad.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mix and Match:&lt;/strong&gt; Then, it starts mixing and matching those letters to make words. It tries all possible combinations by adding one letter at a time and keeps track of the words it can create.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keep Going:&lt;/strong&gt; It does this for all the digits in the sequence, one after the other. Each time, it adds more letters to the words it's making.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Save the Magic Words:&lt;/strong&gt; Whenever it finishes a combination (when it has used all the digits), it saves that word in a special list.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Return the Magic Words:&lt;/strong&gt; After it has gone through all the possibilities, it gives you back the list of magic words it found.&lt;/p&gt;

&lt;h2&gt;
  
  
  code:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.ArrayList;
import java.util.List;

class Solution {
    static String[] keypad = { "", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };

    public List&amp;lt;String&amp;gt; letterCombinations(String digits) {
        List&amp;lt;String&amp;gt; stringList = new ArrayList&amp;lt;&amp;gt;();
        if (digits.length() == 0) {
            return stringList;
        }

        letterCombinationsRecursive(digits, 0, "", stringList);

        return stringList;
    }

    private void letterCombinationsRecursive(String digits, int index, String ans, List&amp;lt;String&amp;gt; stringList) {
        if (index == digits.length()) {
            stringList.add(ans);
            return;
        }

        String key = keypad[digits.charAt(index) - '0'];

        for (int i = 0; i &amp;lt; key.length(); i++) {
            letterCombinationsRecursive(digits, index + 1, ans + key.charAt(i), stringList);
        }
    }   
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Happy coding,&lt;br&gt;
shiva&lt;/p&gt;

</description>
      <category>java</category>
      <category>coding</category>
      <category>programming</category>
      <category>career</category>
    </item>
    <item>
      <title>Solving the "Search Insert Position" Problem on LeetCode</title>
      <dc:creator>Bollam Shiva Shankara Varapras</dc:creator>
      <pubDate>Thu, 07 Sep 2023 04:53:17 +0000</pubDate>
      <link>https://dev.to/shivabollam07/solving-the-search-insert-position-problem-on-leetcode-using-binary-search-og</link>
      <guid>https://dev.to/shivabollam07/solving-the-search-insert-position-problem-on-leetcode-using-binary-search-og</guid>
      <description>&lt;h2&gt;
  
  
  35. Search Insert Position
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Question Type:&lt;/strong&gt; Easy&lt;br&gt;
&lt;strong&gt;Liked by :&lt;/strong&gt;14.6K&lt;br&gt;
&lt;strong&gt;Disliked by:&lt;/strong&gt; 630&lt;/p&gt;

&lt;h2&gt;
  
  
  Companies asked this Question:
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Company name : No of Times&lt;/em&gt;&lt;br&gt;
Amazon 4&lt;br&gt;
Google 2&lt;br&gt;
Apple 8&lt;br&gt;
Microsoft 5&lt;br&gt;
Adobe 4&lt;br&gt;
Yahoo 2&lt;br&gt;
Bloomberg 2&lt;br&gt;
Facebook 7&lt;br&gt;
VMware 5&lt;br&gt;
Uber 4&lt;br&gt;
LinkedIn 2&lt;br&gt;
TikTok 2&lt;br&gt;
tcs 2&lt;/p&gt;

&lt;p&gt;Given a sorted &lt;code&gt;array&lt;/code&gt; of distinct integers and a &lt;code&gt;target&lt;/code&gt; value, return the &lt;code&gt;index&lt;/code&gt; if the target is found. If not, return the &lt;code&gt;index&lt;/code&gt; where it would be if it were inserted in &lt;code&gt;order&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You must write an algorithm with &lt;code&gt;O(log n)&lt;/code&gt; runtime complexity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1:&lt;/strong&gt;&lt;br&gt;
Input: &lt;code&gt;nums = [1,3,5,6], target = 5&lt;/code&gt;&lt;br&gt;
Output: &lt;code&gt;2&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 2:&lt;/strong&gt;&lt;br&gt;
Input: &lt;code&gt;nums = [1,3,5,6], target = 2&lt;/code&gt;&lt;br&gt;
Output: &lt;code&gt;1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 3:&lt;/strong&gt;&lt;br&gt;
Input: &lt;code&gt;nums = [1,3,5,6], target = 7&lt;/code&gt;&lt;br&gt;
Output: &lt;code&gt;4&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Constraints:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;1 &amp;lt;= nums.length &amp;lt;= 104&lt;/code&gt;&lt;br&gt;
&lt;code&gt;-104 &amp;lt;= nums[i] &amp;lt;= 104&lt;/code&gt;&lt;br&gt;
&lt;code&gt;nums&lt;/code&gt; contains &lt;strong&gt;distinct&lt;/strong&gt; values sorted in &lt;strong&gt;ascending&lt;/strong&gt; order.&lt;br&gt;
&lt;code&gt;-104 &amp;lt;= target &amp;lt;= 104&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Approach:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Initialize Pointers:&lt;/strong&gt;&lt;br&gt;
Initialize two pointers, start and end, to represent the search range within the sorted array.start initially points to the first element (index 0), and end points to the last element (index nums.length - 1).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Binary Search Loop:&lt;/strong&gt;&lt;br&gt;
Enter a while loop that continues as long as start is less than or equal to end.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Calculate Middle Index:&lt;/strong&gt;&lt;br&gt;
Calculate the middle index mid as start + (end - start) / 2. This ensures that the middle index is always rounded down to an integer, avoiding potential overflow issues.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Compare with Target:&lt;/strong&gt;&lt;br&gt;
Check if the element at index mid is equal to the target value.&lt;br&gt;
If they are equal, return mid as the index where the target is found.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adjust Pointers:&lt;/strong&gt;&lt;br&gt;
If the element at index mid is greater than the target, update end to mid - 1 to search in the left half of the current range.&lt;br&gt;
If the element at index mid is less than the target, update start to mid + 1 to search in the right half of the current range.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Return Insertion Point:&lt;/strong&gt;&lt;br&gt;
If the while loop exits without finding the target (i.e., start becomes greater than end), return start as the index where the target should be inserted.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code(in Java):
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Solution {
    public int searchInsert(int[] nums, int target) {
         int start = 0;
         int end = nums.length - 1;

         while(start &amp;lt;= end){
             int mid = start +(end - start) / 2;
             if(nums[mid] == target) return mid;
             if(nums[mid] &amp;gt; target) end = mid - 1;
             if(nums[mid] &amp;lt; target) start = mid + 1;
         }
         return start;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Time Complexity Analysis:&lt;/strong&gt;&lt;br&gt;
Binary search has a time complexity of O(log n), where n is the number of elements in the array. This approach ensures that the search is performed efficiently.&lt;/p&gt;

&lt;p&gt;Happy coding,&lt;br&gt;
shiva&lt;/p&gt;

</description>
      <category>programming</category>
      <category>coding</category>
      <category>java</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
