<?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: Ankush Chudiwal</title>
    <description>The latest articles on DEV Community by Ankush Chudiwal (@ankushchudiwal).</description>
    <link>https://dev.to/ankushchudiwal</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%2F2312149%2Fe47381fa-9105-4e88-95f7-dc2acc0ce030.png</url>
      <title>DEV Community: Ankush Chudiwal</title>
      <link>https://dev.to/ankushchudiwal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ankushchudiwal"/>
    <language>en</language>
    <item>
      <title>DSA problem - Second Largest</title>
      <dc:creator>Ankush Chudiwal</dc:creator>
      <pubDate>Sat, 23 Nov 2024 19:17:51 +0000</pubDate>
      <link>https://dev.to/ankushchudiwal/dsa-problem-second-largest-1146</link>
      <guid>https://dev.to/ankushchudiwal/dsa-problem-second-largest-1146</guid>
      <description>&lt;h3&gt;
  
  
  Explanation of Code: Finding the Second-Largest Element in an Array
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/Ankush1oo8/GFG160" rel="noopener noreferrer"&gt;Git Repo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The code provides a solution to determine the second-largest element in an array. This is achieved through a single traversal while maintaining two variables to track the largest and second-largest values.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Code Walkthrough&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Solution&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;second_largest&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Code Here&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Special case: If the array has exactly 2 elements, return the smaller one&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;secmax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Math&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;min&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;],&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;]);&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;secmax&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// Initialize variables to track the largest and second largest values&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;max&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;secmax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Traverse the array&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// If the current element is greater than the current largest&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;max&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;secmax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;max&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Update second largest&lt;/span&gt;
                &lt;span class="n"&gt;max&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt; &lt;span class="c1"&gt;// Update largest&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
            &lt;span class="c1"&gt;// If the current element is less than the largest but greater than the current second largest&lt;/span&gt;
            &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="nf"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;max&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;secmax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Math&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;max&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;],&lt;/span&gt; &lt;span class="n"&gt;secmax&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// Return the second largest value&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;secmax&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;Step-by-Step Explanation&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;1. Handle Edge Cases&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;If the array contains exactly two elements:

&lt;ul&gt;
&lt;li&gt;The second-largest element is simply the smaller of the two values.&lt;/li&gt;
&lt;li&gt;Example: For &lt;code&gt;[3, 5]&lt;/code&gt;, the second largest is &lt;code&gt;3&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;2. Variables Initialization&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;max&lt;/code&gt;&lt;/strong&gt;: Tracks the largest element in the array.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;secmax&lt;/code&gt;&lt;/strong&gt;: Tracks the second-largest element.&lt;/li&gt;
&lt;li&gt;Both are initialized to &lt;code&gt;-1&lt;/code&gt; as a default value.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;3. Traverse the Array&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The loop iterates through the array elements to update the largest and second-largest values:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;When the current element is greater than &lt;code&gt;max&lt;/code&gt;&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Update &lt;code&gt;secmax&lt;/code&gt; to the previous value of &lt;code&gt;max&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Update &lt;code&gt;max&lt;/code&gt; to the current element.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;When the current element is smaller than &lt;code&gt;max&lt;/code&gt; but greater than &lt;code&gt;secmax&lt;/code&gt;&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Update &lt;code&gt;secmax&lt;/code&gt; to the current element.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;4. Return the Result&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;After the loop, &lt;code&gt;secmax&lt;/code&gt; holds the second-largest value.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Complexity Analysis&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Time Complexity&lt;/strong&gt;:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The array is traversed once.&lt;/li&gt;
&lt;li&gt;Total time complexity: &lt;strong&gt;O(n)&lt;/strong&gt;, where &lt;code&gt;n&lt;/code&gt; is the length of the array.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Space Complexity&lt;/strong&gt;:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The algorithm uses constant space for &lt;code&gt;max&lt;/code&gt; and &lt;code&gt;secmax&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Space complexity: &lt;strong&gt;O(1)&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Example Walkthrough&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Example 1:
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Input&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;ul&gt;
&lt;li&gt;Initialize &lt;code&gt;max = -1&lt;/code&gt;, &lt;code&gt;secmax = -1&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Traverse the array:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;1&lt;/code&gt;: &lt;code&gt;max = 1&lt;/code&gt;, &lt;code&gt;secmax = -1&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;4&lt;/code&gt;: &lt;code&gt;max = 4&lt;/code&gt;, &lt;code&gt;secmax = 1&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;3&lt;/code&gt;: &lt;code&gt;secmax = 3&lt;/code&gt; (since &lt;code&gt;3 &amp;gt; secmax&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;2&lt;/code&gt;: No update (since &lt;code&gt;2 &amp;lt; secmax&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Final values: &lt;code&gt;max = 4&lt;/code&gt;, &lt;code&gt;secmax = 3&lt;/code&gt;.&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="mi"&gt;3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h4&gt;
  
  
  Example 2:
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Input&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;ul&gt;
&lt;li&gt;All elements are equal, so no second largest exists.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;secmax&lt;/code&gt; remains &lt;code&gt;-1&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;Advantages&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The algorithm efficiently finds the second-largest element in a single traversal.&lt;/li&gt;
&lt;li&gt;It is memory-efficient as it uses constant space.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Good DSA problem -ROTATE ARRAY</title>
      <dc:creator>Ankush Chudiwal</dc:creator>
      <pubDate>Sat, 23 Nov 2024 19:14:02 +0000</pubDate>
      <link>https://dev.to/ankushchudiwal/good-dsa-problem-rotate-array-1op0</link>
      <guid>https://dev.to/ankushchudiwal/good-dsa-problem-rotate-array-1op0</guid>
      <description>&lt;p&gt;&lt;a href="https://github.com/Ankush1oo8/GFG160" rel="noopener noreferrer"&gt;Check the git repo&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Explanation of Code: Rotating an Array by &lt;code&gt;d&lt;/code&gt; Elements (Counter-Clockwise)
&lt;/h3&gt;

&lt;p&gt;The code provides a solution to rotate an array &lt;code&gt;arr&lt;/code&gt; by &lt;code&gt;d&lt;/code&gt; elements in a counter-clockwise direction using the reversal algorithm.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Code Walkthrough&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Solution&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Function to rotate an array by d elements in counter-clockwise direction.&lt;/span&gt;
    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;rotateArr&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;[],&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Edge case: If the array has only one element or no rotation needed&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// Normalize d in case it's greater than or equal to array length&lt;/span&gt;
        &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Step 1: Reverse the first d elements&lt;/span&gt;
        &lt;span class="n"&gt;reverse&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Step 2: Reverse the remaining elements&lt;/span&gt;
        &lt;span class="n"&gt;reverse&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Step 3: Reverse the entire array&lt;/span&gt;
        &lt;span class="n"&gt;reverse&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Helper function to reverse elements in the array&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;reverse&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;[],&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// Swap elements at start and end&lt;/span&gt;
            &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
            &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
            &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;temp&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="o"&gt;++;&lt;/span&gt;
            &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="o"&gt;--;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;Step-by-Step Explanation&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;1. Handle Edge Cases&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;If the array length is &lt;code&gt;1&lt;/code&gt; or less (&lt;code&gt;n &amp;lt;= 1&lt;/code&gt;), or if no rotation is needed (&lt;code&gt;d &amp;lt;= 0&lt;/code&gt;), the function exits early.&lt;/li&gt;
&lt;li&gt;No modifications are performed on such inputs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;2. Normalize the Rotation Count&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;If &lt;code&gt;d&lt;/code&gt; is greater than or equal to the array length (&lt;code&gt;d &amp;gt;= n&lt;/code&gt;), rotating by &lt;code&gt;d&lt;/code&gt; elements is equivalent to rotating by &lt;code&gt;d % n&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;This ensures the rotation count remains within bounds.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;3. Reverse Algorithm for Rotation&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The reversal algorithm rotates the array in three steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Reverse the first &lt;code&gt;d&lt;/code&gt; elements&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Example: For an array &lt;code&gt;[1, 2, 3, 4, 5]&lt;/code&gt; and &lt;code&gt;d = 2&lt;/code&gt;, reverse &lt;code&gt;[1, 2]&lt;/code&gt; to get &lt;code&gt;[2, 1, 3, 4, 5]&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Reverse the remaining &lt;code&gt;n - d&lt;/code&gt; elements&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reverse &lt;code&gt;[3, 4, 5]&lt;/code&gt; to get &lt;code&gt;[2, 1, 5, 4, 3]&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Reverse the entire array&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reverse &lt;code&gt;[2, 1, 5, 4, 3]&lt;/code&gt; to get &lt;code&gt;[3, 4, 5, 1, 2]&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;4. Helper Function: &lt;code&gt;reverse&lt;/code&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;reverse&lt;/code&gt; function swaps elements in the array between the specified &lt;code&gt;start&lt;/code&gt; and &lt;code&gt;end&lt;/code&gt; indices.&lt;/li&gt;
&lt;li&gt;It iteratively swaps elements until the pointers meet.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Complexity Analysis&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Time Complexity&lt;/strong&gt;:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reversing subsets of the array involves traversing all elements exactly once.&lt;/li&gt;
&lt;li&gt;Total time complexity: &lt;strong&gt;O(n)&lt;/strong&gt;, where &lt;code&gt;n&lt;/code&gt; is the length of the array.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Space Complexity&lt;/strong&gt;:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The algorithm uses constant extra space for swapping elements.&lt;/li&gt;
&lt;li&gt;Space complexity: &lt;strong&gt;O(1)&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Example Walkthrough&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Execution:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Normalize &lt;code&gt;d&lt;/code&gt;: &lt;code&gt;d = 2 % 5 = 2&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Reverse the first &lt;code&gt;d&lt;/code&gt; elements: &lt;code&gt;[1, 2]&lt;/code&gt; → &lt;code&gt;[2, 1]&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;Array becomes: &lt;code&gt;[2, 1, 3, 4, 5]&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Reverse the remaining elements: &lt;code&gt;[3, 4, 5]&lt;/code&gt; → &lt;code&gt;[5, 4, 3]&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;Array becomes: &lt;code&gt;[2, 1, 5, 4, 3]&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Reverse the entire array: &lt;code&gt;[2, 1, 5, 4, 3]&lt;/code&gt; → &lt;code&gt;[3, 4, 5, 1, 2]&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;Advantages&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The reversal algorithm is efficient and does not require additional space.&lt;/li&gt;
&lt;li&gt;It provides a systematic approach to solving array rotation problems.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>🚀 Made A AI-Powered Content Summarizer Chrome Extension</title>
      <dc:creator>Ankush Chudiwal</dc:creator>
      <pubDate>Sat, 16 Nov 2024 16:37:20 +0000</pubDate>
      <link>https://dev.to/ankushchudiwal/introducing-ai-powered-content-summarizer-chrome-extension-54ep</link>
      <guid>https://dev.to/ankushchudiwal/introducing-ai-powered-content-summarizer-chrome-extension-54ep</guid>
      <description>&lt;p&gt;🔗 &lt;a href="https://github.com/Ankush1oo8/ai-content-summarizer" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;What is it?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Tired of spending hours reading long articles or web pages? The &lt;strong&gt;AI-Powered Content Summarizer&lt;/strong&gt; extension is here to save your time and effort! Using ApyHub's AI summarization API, this tool condenses web content into short, medium, or long summaries—all at the click of a button.&lt;/p&gt;

&lt;p&gt;✅ &lt;strong&gt;Available for Chrome and Firefox&lt;/strong&gt;!  &lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;✨ Features&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Summarize web pages effortlessly in seconds.
&lt;/li&gt;
&lt;li&gt;Choose between &lt;strong&gt;Short&lt;/strong&gt;, &lt;strong&gt;Medium&lt;/strong&gt;, or &lt;strong&gt;Long&lt;/strong&gt; summaries.
&lt;/li&gt;
&lt;li&gt;Simple popup interface for quick access.
&lt;/li&gt;
&lt;li&gt;Compatible with &lt;strong&gt;Chrome&lt;/strong&gt; and &lt;strong&gt;Firefox&lt;/strong&gt; browsers.
&lt;/li&gt;
&lt;li&gt;Powered by &lt;strong&gt;ApyHub AI&lt;/strong&gt; for concise and accurate results.
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;How to Use&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Chrome&lt;/strong&gt;
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Clone the repository:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   git clone https://github.com/Ankush1oo8/ai-content-summarizer.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Load the extension:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to &lt;code&gt;chrome://extensions/&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;Enable &lt;strong&gt;Developer Mode&lt;/strong&gt;.
&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Load Unpacked&lt;/strong&gt; and select the project folder.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add your &lt;strong&gt;ApyHub API Key&lt;/strong&gt; in the &lt;code&gt;background.js&lt;/code&gt; file.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Navigate to any webpage, click the extension, and choose your summary length!  &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Firefox&lt;/strong&gt;
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Clone the repository as above.
&lt;/li&gt;
&lt;li&gt;Open Firefox, go to &lt;code&gt;about:debugging#/runtime/this-firefox&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Load Temporary Add-on&lt;/strong&gt; and select the &lt;code&gt;manifest.json&lt;/code&gt; file from the project folder.
&lt;/li&gt;
&lt;li&gt;Add the API key as instructed in the code files.
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;🔧 How It Was Made&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;AI-Powered Content Summarizer&lt;/strong&gt; was developed with simplicity and user-friendliness in mind. Here's the step-by-step process:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Identifying the Problem&lt;/strong&gt;:&lt;br&gt;&lt;br&gt;
We wanted a tool to simplify web content for users who value their time—students, professionals, or casual readers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Choosing the Right API&lt;/strong&gt;:&lt;br&gt;&lt;br&gt;
We integrated ApyHub's AI summarization API for its speed, accuracy, and versatility.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Building the Extension&lt;/strong&gt;:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Manifest v3&lt;/strong&gt; for Chrome to define permissions and functionality.
&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;background script&lt;/strong&gt; to handle API calls and processing.
&lt;/li&gt;
&lt;li&gt;A clean &lt;strong&gt;popup interface&lt;/strong&gt; (HTML, CSS, JavaScript) for user interaction.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Testing on Browsers&lt;/strong&gt;:&lt;br&gt;&lt;br&gt;
The extension was tested on Chrome and Firefox to ensure compatibility and seamless performance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Publishing &amp;amp; Open-Sourcing&lt;/strong&gt;:&lt;br&gt;&lt;br&gt;
By making the code open-source, we encourage developers to use, improve, and contribute to the project.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Why You’ll Love It&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This extension is perfect for anyone who:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Wants concise summaries of long content.
&lt;/li&gt;
&lt;li&gt;Needs to save time while staying informed.
&lt;/li&gt;
&lt;li&gt;Prefers a straightforward, easy-to-use tool.
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;🛠️ &lt;strong&gt;Explore the Code&lt;/strong&gt;: Check out the full project on GitHub: &lt;a href="https://github.com/Ankush1oo8/ai-content-summarizer" rel="noopener noreferrer"&gt;ai-content-summarizer&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;🌟 &lt;strong&gt;Feedback Welcome&lt;/strong&gt;: Found a bug or have ideas for improvement? Feel free to open an issue or contribute!  &lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;License&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This project is licensed under the MIT License. Learn more in the repository.  &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
