<?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[LeetCode Coding Solutions by Akash👨🏻‍💻 - Medium]]></title>
        <description><![CDATA[This section contains solution to leetCode Problems - Medium]]></description>
        <link>https://medium.com/leetcode-coding-solutions?source=rss----e5b5d6d6a90b---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>LeetCode Coding Solutions by Akash👨🏻‍💻 - Medium</title>
            <link>https://medium.com/leetcode-coding-solutions?source=rss----e5b5d6d6a90b---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 10:01:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/leetcode-coding-solutions" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[1. Two Sum]]></title>
            <link>https://medium.com/leetcode-coding-solutions/1-two-sum-79f38b86e507?source=rss----e5b5d6d6a90b---4</link>
            <guid isPermaLink="false">https://medium.com/p/79f38b86e507</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[alogrithm]]></category>
            <category><![CDATA[leetcode-easy]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Akash Dhingra]]></dc:creator>
            <pubDate>Fri, 19 Jul 2024 22:14:07 GMT</pubDate>
            <atom:updated>2024-07-19T22:13:54.335Z</atom:updated>
            <content:encoded><![CDATA[<h3>Easy</h3><p>Given an array of integers nums and an integer target, return <em>indices of the two numbers such that they add up to </em><em>target</em>.</p><p>You may assume that each input would have <em>exactly</em> one solution, and you may not use the <em>same</em> element twice.</p><p>You can return the answer in any order.</p><p>Example 1:</p><pre>Input: nums = [2,7,11,15], target = 9<br>Output: [0,1]<br>Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].</pre><p>Example 2:</p><pre>Input: nums = [3,2,4], target = 6<br>Output: [1,2]</pre><p>Example 3:</p><pre>Input: nums = [3,3], target = 6<br>Output: [0,1]</pre><p>Constraints:</p><ul><li>2 &lt;= nums.length &lt;= 104</li><li>-109 &lt;= nums[i] &lt;= 109</li><li>-109 &lt;= target &lt;= 109</li><li>Only one valid answer exists.</li></ul><p>Follow-up: Can you come up with an algorithm that is less than O(n2) time complexity?</p><p><strong>Solution:</strong></p><p><em>Approach 1 [Naive Approach]</em>:</p><pre>// Two sum<br>class Solution {<br>    public int[] twoSum(int[] nums, int target) {<br>        int a = nums.length;<br>        int arr[] = new int[2];<br>        <br>        for(int i=0;i&lt;a;i++)<br>        {<br>            for(int j=i+1;j&lt;a;j++)<br>            {<br>                if((nums[i]+nums[j])==target){<br>                    arr[0]=i;<br>                    arr[1]=j;<br>                    break;<br>                }<br>                                        <br>            }<br>        }<br>        return arr;<br>        <br>    }<br>}</pre><p><em>Approach 2 [Optimized Approach]</em>:</p><pre>import java.util.HashMap;<br>import java.util.Map;<br><br>class Solution {<br>    public int[] twoSum(int[] nums, int target) {<br>        Map&lt;Integer, Integer&gt; map = new HashMap&lt;&gt;();<br>        for (int i = 0; i &lt; nums.length; i++) {<br>            int complement = target - nums[i];<br>            if (map.containsKey(complement)) {<br>                return new int[] { map.get(complement), i };<br>            }<br>            map.put(nums[i], i);<br>        }<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79f38b86e507" width="1" height="1" alt=""><hr><p><a href="https://medium.com/leetcode-coding-solutions/1-two-sum-79f38b86e507">1. Two Sum</a> was originally published in <a href="https://medium.com/leetcode-coding-solutions">LeetCode Coding Solutions by Akash👨🏻‍💻</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[125. Valid Palindrome]]></title>
            <link>https://medium.com/leetcode-coding-solutions/125-valid-palindrome-3f2abe3fc653?source=rss----e5b5d6d6a90b---4</link>
            <guid isPermaLink="false">https://medium.com/p/3f2abe3fc653</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[leetcode]]></category>
            <dc:creator><![CDATA[Akash Dhingra]]></dc:creator>
            <pubDate>Wed, 19 Jul 2023 02:29:38 GMT</pubDate>
            <atom:updated>2023-07-19T02:29:29.385Z</atom:updated>
            <content:encoded><![CDATA[<h3>Easy</h3><p>A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.</p><p>Given a string s, return true<em> if it is a palindrome, or </em>false<em> otherwise</em>.</p><p>Example 1:</p><pre>Input: s = &quot;A man, a plan, a canal: Panama&quot;<br>Output: true<br>Explanation: &quot;amanaplanacanalpanama&quot; is a palindrome.</pre><p>Example 2:</p><pre>Input: s = &quot;race a car&quot;<br>Output: false<br>Explanation: &quot;raceacar&quot; is not a palindrome.</pre><p>Example 3:</p><pre>Input: s = &quot; &quot;<br>Output: true<br>Explanation: s is an empty string &quot;&quot; after removing non-alphanumeric characters.<br>Since an empty string reads the same forward and backward, it is a palindrome.</pre><p>Constraints:</p><ul><li>1 &lt;= s.length &lt;= 2 * 105</li><li>s consists only of printable ASCII characters.</li></ul><p><strong>Solution:</strong></p><p><em>Approach 1</em>:</p><pre>class Solution {<br>    public boolean isPalindrome(String s) {<br>        String str = s.toLowerCase().replaceAll(&quot;[^a-z0-9]&quot;,&quot;&quot;);<br>        int i = 0;<br>        int j = str.length()-1;<br>        while(j&gt;=i){<br>            if(str.charAt(i) != str.charAt(j)){<br>                return false;<br>            }<br>            <br>            i++;<br>            j--;<br>        }<br>        return true;<br>        <br>    }<br>    <br>}</pre><p><em>Approach 2</em>:</p><pre> class Solution {<br>     public boolean isPalindrome(String s) {<br>        <br>         String user_string = &quot;&quot;;<br>         String reverse_string = &quot;&quot;;<br>        <br>         for(int i=0;i&lt;s.length();i++)<br>         {<br>             if(s.charAt(i)&gt;=&#39;a&#39; &amp;&amp; s.charAt(i) &lt;=&#39;z&#39; || s.charAt(i)&gt;=&#39;A&#39; &amp;&amp; s.charAt(i) &lt;=&#39;Z&#39;  || s.charAt(i)&gt;= &#39;0&#39; &amp;&amp; s.charAt(i) &lt;=&#39;9&#39;)<br>             {<br>                 user_string = user_string + Character.toLowerCase(s.charAt(i));<br>             }<br>            <br>         }<br>        <br>         for(int j=user_string.length()-1;j&gt;=0;j--){<br>             reverse_string = reverse_string + user_string.charAt(j);<br>         }<br>        <br>         if(user_string.equals(reverse_string))<br>             return true;<br>         return false;<br>     }<br>    <br> }</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f2abe3fc653" width="1" height="1" alt=""><hr><p><a href="https://medium.com/leetcode-coding-solutions/125-valid-palindrome-3f2abe3fc653">125. Valid Palindrome</a> was originally published in <a href="https://medium.com/leetcode-coding-solutions">LeetCode Coding Solutions by Akash👨🏻‍💻</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[111. Minimum depth of a binary tree]]></title>
            <link>https://medium.com/leetcode-coding-solutions/111-minimum-depth-of-a-binary-tree-473e3689f2a4?source=rss----e5b5d6d6a90b---4</link>
            <guid isPermaLink="false">https://medium.com/p/473e3689f2a4</guid>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Akash Dhingra]]></dc:creator>
            <pubDate>Wed, 19 Jul 2023 02:26:54 GMT</pubDate>
            <atom:updated>2023-07-19T02:26:45.754Z</atom:updated>
            <content:encoded><![CDATA[<h3>Easy</h3><p>Given a binary tree, find its minimum depth.</p><p>The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.</p><p>Note: A leaf is a node with no children.</p><p>Example 1:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/0*t9eUtD6OObXr-5xW" /></figure><pre>Input: root = [3,9,20,null,null,15,7]<br>Output: 2</pre><p>Example 2:</p><pre>Input: root = [2,null,3,null,4,null,5,null,6]<br>Output: 5</pre><p>Constraints:</p><ul><li>The number of nodes in the tree is in the range [0, 105].</li><li>-1000 &lt;= Node.val &lt;= 1000</li></ul><p><strong>Solution:</strong></p><pre>/**<br> * Definition for a binary tree node.<br> * public class TreeNode {<br> *     int val;<br> *     TreeNode left;<br> *     TreeNode right;<br> *     TreeNode() {}<br> *     TreeNode(int val) { this.val = val; }<br> *     TreeNode(int val, TreeNode left, TreeNode right) {<br> *         this.val = val;<br> *         this.left = left;<br> *         this.right = right;<br> *     }<br> * }<br> */<br>class Solution {<br>    public int minDepth(TreeNode root) {<br>        if(root == null)<br>            return 0;<br>        int left = minDepth(root.left);<br>        int right = minDepth(root.right);<br>        if(left == 0 || right == 0)<br>            return left+right+1;<br>        else<br>            return Math.min(left,right)+1;<br>        <br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=473e3689f2a4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/leetcode-coding-solutions/111-minimum-depth-of-a-binary-tree-473e3689f2a4">111. Minimum depth of a binary tree</a> was originally published in <a href="https://medium.com/leetcode-coding-solutions">LeetCode Coding Solutions by Akash👨🏻‍💻</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[110. Balanced Binary Tree]]></title>
            <link>https://medium.com/leetcode-coding-solutions/110-balanced-binary-tree-60dd1e8ecf65?source=rss----e5b5d6d6a90b---4</link>
            <guid isPermaLink="false">https://medium.com/p/60dd1e8ecf65</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Akash Dhingra]]></dc:creator>
            <pubDate>Wed, 19 Jul 2023 02:25:31 GMT</pubDate>
            <atom:updated>2023-07-19T02:25:22.290Z</atom:updated>
            <content:encoded><![CDATA[<h3>Easy</h3><p>Given a binary tree, determine if it is height-balanced.</p><p>Example 1:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/0*sZRUL76TnTKLp4wN" /></figure><pre>Input: root = [3,9,20,null,null,15,7]<br>Output: true</pre><p>Example 2:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/0*yLdbj2Cvu9IYuCO6" /></figure><pre>Input: root = [1,2,2,3,3,null,null,4,4]<br>Output: false</pre><p>Example 3:</p><pre>Input: root = []<br>Output: true</pre><p>Constraints:</p><ul><li>The number of nodes in the tree is in the range [0, 5000].</li><li>-104 &lt;= Node.val &lt;= 104</li></ul><p><strong>Solution:</strong></p><pre>/**<br> * Definition for a binary tree node.<br> * public class TreeNode {<br> *     int val;<br> *     TreeNode left;<br> *     TreeNode right;<br> *     TreeNode() {}<br> *     TreeNode(int val) { this.val = val; }<br> *     TreeNode(int val, TreeNode left, TreeNode right) {<br> *         this.val = val;<br> *         this.left = left;<br> *         this.right = right;<br> *     }<br> * }<br> */<br><br>// Get the height of left and right subtrees using dfs traversal. Return true if the // difference between heights is not more than 1 and left and right subtrees are <br>// balanced, otherwise return false. <br><br>class Solution {<br>    public boolean isBalanced(TreeNode root) {<br>        if(root == null)<br>            return true;<br>        <br>        int l = height(root.left);<br>        int r = height(root.right);<br>        <br>        if(Math.abs(l-r) &lt;=1 &amp;&amp; isBalanced(root.left) &amp;&amp; isBalanced(root.right))<br>            return true;<br>        else<br>            return false;<br>        <br>    }<br>    <br>    public int height(TreeNode root){<br>        if(root == null)<br>            return 0;<br>        else<br>            return 1+ Math.max(height(root.left),height(root.right));<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60dd1e8ecf65" width="1" height="1" alt=""><hr><p><a href="https://medium.com/leetcode-coding-solutions/110-balanced-binary-tree-60dd1e8ecf65">110. Balanced Binary Tree</a> was originally published in <a href="https://medium.com/leetcode-coding-solutions">LeetCode Coding Solutions by Akash👨🏻‍💻</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[101. Symmetric Tree]]></title>
            <link>https://medium.com/leetcode-coding-solutions/101-symmetric-tree-197eb77506a3?source=rss----e5b5d6d6a90b---4</link>
            <guid isPermaLink="false">https://medium.com/p/197eb77506a3</guid>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Akash Dhingra]]></dc:creator>
            <pubDate>Wed, 19 Jul 2023 02:24:15 GMT</pubDate>
            <atom:updated>2023-07-19T02:24:06.741Z</atom:updated>
            <content:encoded><![CDATA[<h3>Easy</h3><p>Given the root of a binary tree, <em>check whether it is a mirror of itself</em> (i.e., symmetric around its center).</p><p>Example 1:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/0*5Iuex_SOHwfTDdXw" /></figure><pre>Input: root = [1,2,2,3,4,4,3]<br>Output: true</pre><p>Example 2:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/308/0*rxlkekl0RBV_2yMc" /></figure><pre>Input: root = [1,2,2,null,3,null,3]<br>Output: false</pre><p>Constraints:</p><ul><li>The number of nodes in the tree is in the range [1, 1000].</li><li>-100 &lt;= Node.val &lt;= 100</li></ul><p><strong>Solution:</strong></p><pre>/**<br> * Definition for a binary tree node.<br> * public class TreeNode {<br> *     int val;<br> *     TreeNode left;<br> *     TreeNode right;<br> *     TreeNode() {}<br> *     TreeNode(int val) { this.val = val; }<br> *     TreeNode(int val, TreeNode left, TreeNode right) {<br> *         this.val = val;<br> *         this.left = left;<br> *         this.right = right;<br> *     }<br> * }<br> */<br>class Solution {<br>    public boolean isSymmetric(TreeNode root) {<br>        <br>        if (root == null)<br>            return true;<br>        return isSymmetric(root.left, root.right);<br>        <br>    }<br>    <br>    private boolean isSymmetric(TreeNode a, TreeNode b){<br>            if(a==null&amp;&amp;b==null){return true;}<br>            if(a==null||b==null){return false;}<br>            if(a.val!=b.val){return false;}<br>            return isSymmetric(a.left,b.right)&amp;&amp;isSymmetric(a.right,b.left);<br>        }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=197eb77506a3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/leetcode-coding-solutions/101-symmetric-tree-197eb77506a3">101. Symmetric Tree</a> was originally published in <a href="https://medium.com/leetcode-coding-solutions">LeetCode Coding Solutions by Akash👨🏻‍💻</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[66. Plus one]]></title>
            <link>https://medium.com/leetcode-coding-solutions/66-plus-one-d4b044613867?source=rss----e5b5d6d6a90b---4</link>
            <guid isPermaLink="false">https://medium.com/p/d4b044613867</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[leetcode]]></category>
            <dc:creator><![CDATA[Akash Dhingra]]></dc:creator>
            <pubDate>Wed, 19 Jul 2023 02:21:07 GMT</pubDate>
            <atom:updated>2023-07-19T02:20:58.756Z</atom:updated>
            <content:encoded><![CDATA[<h3>Easy</h3><p>You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading 0&#39;s.</p><p>Increment the large integer by one and return <em>the resulting array of digits</em>.</p><p>Example 1:</p><pre>Input: digits = [1,2,3]<br>Output: [1,2,4]<br>Explanation: The array represents the integer 123.<br>Incrementing by one gives 123 + 1 = 124.<br>Thus, the result should be [1,2,4].</pre><p>Example 2:</p><pre>Input: digits = [4,3,2,1]<br>Output: [4,3,2,2]<br>Explanation: The array represents the integer 4321.<br>Incrementing by one gives 4321 + 1 = 4322.<br>Thus, the result should be [4,3,2,2].</pre><p>Example 3:</p><pre>Input: digits = [9]<br>Output: [1,0]<br>Explanation: The array represents the integer 9.<br>Incrementing by one gives 9 + 1 = 10.<br>Thus, the result should be [1,0].</pre><p>Constraints:</p><ul><li>1 &lt;= digits.length &lt;= 100</li><li>0 &lt;= digits[i] &lt;= 9</li><li>digits does not contain any leading 0&#39;s.</li></ul><p><strong>Solution:</strong></p><pre>class Solution {<br>    public int[] plusOne(int[] digits) {<br>       int n = digits.length;<br>        for(int i=n-1;i&gt;=0;i--)<br>        {<br>            if(digits[i] &lt; 9)<br>            {<br>                digits[i]++;<br>                return digits;<br>            }<br>            <br>            digits[i] = 0;<br>        }<br>        <br>        int nums[] = new int[n+1];<br>        nums[0] = 1;<br>        return nums;<br>        <br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4b044613867" width="1" height="1" alt=""><hr><p><a href="https://medium.com/leetcode-coding-solutions/66-plus-one-d4b044613867">66. Plus one</a> was originally published in <a href="https://medium.com/leetcode-coding-solutions">LeetCode Coding Solutions by Akash👨🏻‍💻</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[58. Length of Last Word]]></title>
            <link>https://medium.com/leetcode-coding-solutions/58-length-of-last-word-624ac720739e?source=rss----e5b5d6d6a90b---4</link>
            <guid isPermaLink="false">https://medium.com/p/624ac720739e</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Akash Dhingra]]></dc:creator>
            <pubDate>Wed, 19 Jul 2023 02:19:43 GMT</pubDate>
            <atom:updated>2023-07-19T02:19:33.319Z</atom:updated>
            <content:encoded><![CDATA[<h3>Easy</h3><p>Given a string s consisting of words and spaces, return <em>the length of the last word in the string.</em></p><p>A word is a maximal substring consisting of non-space characters only.</p><p>Example 1:</p><pre>Input: s = &quot;Hello World&quot;<br>Output: 5<br>Explanation: The last word is &quot;World&quot; with length 5.</pre><p>Example 2:</p><pre>Input: s = &quot;   fly me   to   the moon  &quot;<br>Output: 4<br>Explanation: The last word is &quot;moon&quot; with length 4.</pre><p>Example 3:</p><pre>Input: s = &quot;luffy is still joyboy&quot;<br>Output: 6<br>Explanation: The last word is &quot;joyboy&quot; with length 6.</pre><p>Constraints:</p><ul><li>1 &lt;= s.length &lt;= 104</li><li>s consists of only English letters and spaces &#39; &#39;.</li><li>There will be at least one word in s.</li></ul><p><strong>Solution:</strong></p><pre>class Solution {<br>    public int lengthOfLastWord(String s) {<br>        String words[] = s.split(&quot; &quot;);<br>        int n = words.length;<br>        return words[n-1].length();<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=624ac720739e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/leetcode-coding-solutions/58-length-of-last-word-624ac720739e">58. Length of Last Word</a> was originally published in <a href="https://medium.com/leetcode-coding-solutions">LeetCode Coding Solutions by Akash👨🏻‍💻</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[28. Find the index of the first occurrence in a string]]></title>
            <link>https://medium.com/leetcode-coding-solutions/14-longest-common-prefix-59797c176c3f?source=rss----e5b5d6d6a90b---4</link>
            <guid isPermaLink="false">https://medium.com/p/59797c176c3f</guid>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Akash Dhingra]]></dc:creator>
            <pubDate>Wed, 19 Jul 2023 02:11:53 GMT</pubDate>
            <atom:updated>2023-07-19T02:17:22.697Z</atom:updated>
            <content:encoded><![CDATA[<h3>Easy</h3><p>Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.</p><p>Example 1:</p><pre>Input: haystack = &quot;sadbutsad&quot;, needle = &quot;sad&quot;<br>Output: 0<br>Explanation: &quot;sad&quot; occurs at index 0 and 6.<br>The first occurrence is at index 0, so we return 0.</pre><p>Example 2:</p><pre>Input: haystack = &quot;leetcode&quot;, needle = &quot;leeto&quot;<br>Output: -1<br>Explanation: &quot;leeto&quot; did not occur in &quot;leetcode&quot;, so we return -1.</pre><p>Constraints:</p><ul><li>1 &lt;= haystack.length, needle.length &lt;= 104</li><li>haystack and needle consist of only lowercase English characters.</li></ul><p><strong>Solution:</strong></p><pre>class Solution {<br>    public int strStr(String haystack, String needle) {<br>        boolean exist = false;<br>        if(haystack.contains(needle)){<br>            exist = true;<br>        }<br>        <br>        int n = -1;<br>        <br>        if(exist){<br>            for(int i=0;i&lt;haystack.length()-needle.length()+1;i++){<br>                if(haystack.substring(i,i+needle.length()).equals(needle)){<br>                    n = i;<br>                    break;<br>                }<br>            }<br>        }<br>        return n;<br>        <br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59797c176c3f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/leetcode-coding-solutions/14-longest-common-prefix-59797c176c3f">28. Find the index of the first occurrence in a string</a> was originally published in <a href="https://medium.com/leetcode-coding-solutions">LeetCode Coding Solutions by Akash👨🏻‍💻</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[7. Reverse Integer]]></title>
            <link>https://medium.com/leetcode-coding-solutions/7-reverse-integer-3a43e9601406?source=rss----e5b5d6d6a90b---4</link>
            <guid isPermaLink="false">https://medium.com/p/3a43e9601406</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Akash Dhingra]]></dc:creator>
            <pubDate>Thu, 04 May 2023 22:42:33 GMT</pubDate>
            <atom:updated>2023-05-04T22:42:23.918Z</atom:updated>
            <content:encoded><![CDATA[<h3>Medium</h3><p>Given a signed 32-bit integer x, return x<em> with its digits reversed</em>. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0.</p><p>Assume the environment does not allow you to store 64-bit integers (signed or unsigned).</p><p>Example 1:</p><pre>Input: x = 123<br>Output: 321</pre><p>Example 2:</p><pre>Input: x = -123<br>Output: -321</pre><p>Example 3:</p><pre>Input: x = 120<br>Output: 21</pre><p>Constraints:</p><ul><li>-231 &lt;= x &lt;= 231 - 1</li></ul><p><strong>Solution:</strong></p><pre>class Solution {<br>    public int reverse(int x) {<br>        long res = 0;<br>  while(x != 0){<br>   res= res*10 + x%10;<br>   x /= 10;<br>  }<br>  if(res &gt;= Integer.MIN_VALUE &amp;&amp; res &lt;= Integer.MAX_VALUE)<br>   return (int)res;<br>  else<br>   return 0;<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a43e9601406" width="1" height="1" alt=""><hr><p><a href="https://medium.com/leetcode-coding-solutions/7-reverse-integer-3a43e9601406">7. Reverse Integer</a> was originally published in <a href="https://medium.com/leetcode-coding-solutions">LeetCode Coding Solutions by Akash👨🏻‍💻</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[3. Longest Substring Without Repeating Characters]]></title>
            <link>https://medium.com/leetcode-coding-solutions/3-longest-substring-without-repeating-characters-6776d4f391f1?source=rss----e5b5d6d6a90b---4</link>
            <guid isPermaLink="false">https://medium.com/p/6776d4f391f1</guid>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Akash Dhingra]]></dc:creator>
            <pubDate>Thu, 04 May 2023 22:41:16 GMT</pubDate>
            <atom:updated>2023-05-04T22:41:08.438Z</atom:updated>
            <content:encoded><![CDATA[<h3>Medium</h3><p>Given a string s, find the length of the longest substring without repeating characters.</p><p>Example 1:</p><pre>Input: s = &quot;abcabcbb&quot;<br>Output: 3<br>Explanation: The answer is &quot;abc&quot;, with the length of 3.</pre><p>Example 2:</p><pre>Input: s = &quot;bbbbb&quot;<br>Output: 1<br>Explanation: The answer is &quot;b&quot;, with the length of 1.</pre><p>Example 3:</p><pre>Input: s = &quot;pwwkew&quot;<br>Output: 3<br>Explanation: The answer is &quot;wke&quot;, with the length of 3.<br>Notice that the answer must be a substring, &quot;pwke&quot; is a subsequence and not a substring.</pre><p>Constraints:</p><ul><li>0 &lt;= s.length &lt;= 5 * 104</li><li>s consists of English letters, digits, symbols and spaces.</li></ul><p><strong>Solution:</strong></p><pre>class Solution {<br>    public int lengthOfLongestSubstring(String s) {<br>        int n = s.length();<br>        int maxValue = 0;<br>        int[] charArr = new int[128];<br>        Arrays.fill(charArr,-1);<br>        int i = 0;<br>        int j = 0;<br>        <br>        while(j&lt;n){<br>            if(charArr[s.charAt(j)] &gt;=i){<br>                i = charArr[s.charAt(j)] + 1;<br>            }<br>            <br>            charArr[s.charAt(j)] = j;<br>            maxValue = Math.max(maxValue,j-i+1);<br>            j++;<br>        }<br>        return maxValue;<br>        <br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6776d4f391f1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/leetcode-coding-solutions/3-longest-substring-without-repeating-characters-6776d4f391f1">3. Longest Substring Without Repeating Characters</a> was originally published in <a href="https://medium.com/leetcode-coding-solutions">LeetCode Coding Solutions by Akash👨🏻‍💻</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>