<?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: Dharani </title>
    <description>The latest articles on DEV Community by Dharani  (@dharani_boominathan_b1e6b).</description>
    <link>https://dev.to/dharani_boominathan_b1e6b</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%2F3837260%2Ffc561686-6896-41b1-8ec6-94b18726aa2f.png</url>
      <title>DEV Community: Dharani </title>
      <link>https://dev.to/dharani_boominathan_b1e6b</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dharani_boominathan_b1e6b"/>
    <language>en</language>
    <item>
      <title>DNS resolver</title>
      <dc:creator>Dharani </dc:creator>
      <pubDate>Mon, 23 Mar 2026 16:46:12 +0000</pubDate>
      <link>https://dev.to/dharani_boominathan_b1e6b/client-to-server-request-41j7</link>
      <guid>https://dev.to/dharani_boominathan_b1e6b/client-to-server-request-41j7</guid>
      <description>&lt;p&gt;DNS(Domain name system)&lt;/p&gt;

&lt;p&gt;1) It converts Domain name -&amp;gt; IP address&lt;/p&gt;

&lt;p&gt;Ex domain: WWW. google.com&lt;/p&gt;

&lt;p&gt;sub domain : www&lt;br&gt;
second level domain : google&lt;br&gt;
top level domain : .com&lt;/p&gt;

&lt;p&gt;2) work flow:&lt;br&gt;
i) root server: it does not know the ip, it undergoes .com servers&lt;br&gt;
ii) Tld server: it does not know exact ip, ask the server google.com&lt;br&gt;
iii) Sld server: it knows the actual ip, so it returns the ip address of what we have searched.&lt;/p&gt;

&lt;p&gt;3) simple flow diagram:&lt;br&gt;
user-&amp;gt; root -&amp;gt; tld(.com) -&amp;gt; sld(google.com) -&amp;gt; ip address&lt;/p&gt;

</description>
    </item>
    <item>
      <title>IP Address and Subnet</title>
      <dc:creator>Dharani </dc:creator>
      <pubDate>Mon, 23 Mar 2026 16:38:22 +0000</pubDate>
      <link>https://dev.to/dharani_boominathan_b1e6b/ip-address-and-subnet-mip</link>
      <guid>https://dev.to/dharani_boominathan_b1e6b/ip-address-and-subnet-mip</guid>
      <description>&lt;p&gt;IP:&lt;br&gt;
  Internet protocol is a unique number assigned to each device on a network.&lt;br&gt;
ex: 192.168.0.1&lt;br&gt;
  made up of four parts separated by dots&lt;br&gt;
   IP has two parts( Network part, Host part)&lt;/p&gt;

&lt;p&gt;Network part:&lt;br&gt;
 Identifies which the network the device belongs to&lt;br&gt;
   ex: first 3 parts of IP is network part&lt;/p&gt;

&lt;p&gt;Host part:&lt;br&gt;
Identifies which device inside the network&lt;br&gt;
 ex:  last part of IP is host part&lt;/p&gt;

&lt;p&gt;it has 2 version (ipv4 &amp;amp; ipv6)&lt;/p&gt;

&lt;p&gt;1) IPv4 address:&lt;br&gt;
      it has 32bit address&lt;br&gt;
      consider(0-255)&lt;br&gt;
     128 64 32 16 8 4 2 1 (add each element)&lt;/p&gt;

&lt;p&gt;2) IPv6 address:&lt;br&gt;
    it has 128 bit address&lt;/p&gt;

&lt;p&gt;SUBNET:&lt;br&gt;
subnet =  dividing a larger network into smaller networks&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Two Sum and Sorted Two Sum</title>
      <dc:creator>Dharani </dc:creator>
      <pubDate>Sun, 22 Mar 2026 05:40:50 +0000</pubDate>
      <link>https://dev.to/dharani_boominathan_b1e6b/two-sum-and-sorted-two-sum-4c98</link>
      <guid>https://dev.to/dharani_boominathan_b1e6b/two-sum-and-sorted-two-sum-4c98</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;The Two Sum problem is one of the most popular questions in programming interviews. It helps in understanding arrays, hashing, and two-pointer techniques.&lt;/p&gt;




&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Two Sum
&lt;/h3&gt;

&lt;p&gt;Given an array of integers and a target value, return the indices of the two numbers such that they add up to the target.&lt;/p&gt;

&lt;h3&gt;
  
  
  Two Sum II (Sorted Array)
&lt;/h3&gt;

&lt;p&gt;Given a sorted array, find two numbers such that they add up to a target. Return their indices.&lt;/p&gt;




&lt;h2&gt;
  
  
  💡 Approach 1: Two Sum (Using Hash Map)
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Create a dictionary to store numbers and their indices
&lt;/li&gt;
&lt;li&gt;For each element:

&lt;ul&gt;
&lt;li&gt;Find complement = target - element
&lt;/li&gt;
&lt;li&gt;Check if complement exists in dictionary
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;If yes → return indices
&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Python Code (Two Sum)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
python
def two_sum(nums, target):
    hashmap = {}

    for i, num in enumerate(nums):
        complement = target - num

        if complement in hashmap:
            return [hashmap[complement], i]

        hashmap[num] = i

Approach 2: Two Sum II (Sorted Array - Two Pointer)
Use two pointers:
left = 0
right = n - 1
Calculate sum:
If sum == target → return indices
If sum &amp;lt; target → move left
If sum &amp;gt; target → move right

python code (sorted Two sum)

def two_sum_sorted(nums, target):
    left, right = 0, len(nums) - 1

    while left &amp;lt; right:
        total = nums[left] + nums[right]

        if total == target:
            return [left, right]
        elif total &amp;lt; target:
            left += 1
        else:
            right -= 1


## Input
 nums = [2, 7, 11, 15]
 target = 9

## output
 [0,1]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>python</category>
      <category>dsa</category>
      <category>arrays</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Kadanes Algorithm - p2</title>
      <dc:creator>Dharani </dc:creator>
      <pubDate>Sun, 22 Mar 2026 05:31:50 +0000</pubDate>
      <link>https://dev.to/dharani_boominathan_b1e6b/kadanes-algorithm-p2-3j0</link>
      <guid>https://dev.to/dharani_boominathan_b1e6b/kadanes-algorithm-p2-3j0</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Kadane’s Algorithm is an efficient method used to find the maximum sum of a contiguous subarray within a given array. It is widely used in dynamic programming and interview problems.&lt;/p&gt;




&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;p&gt;Given an array of integers, find the maximum sum of a contiguous subarray (containing at least one element).&lt;/p&gt;

&lt;p&gt;A subarray is a continuous part of an array.&lt;/p&gt;




&lt;h2&gt;
  
  
  Approach (Kadane’s Algorithm)
&lt;/h2&gt;

&lt;p&gt;We use two variables:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;current_sum → stores current subarray sum
&lt;/li&gt;
&lt;li&gt;max_sum → stores maximum sum found so far
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Steps:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Initialize:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;current_sum = 0
&lt;/li&gt;
&lt;li&gt;max_sum = -∞
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Traverse the array:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add element to current_sum
&lt;/li&gt;
&lt;li&gt;Update max_sum
&lt;/li&gt;
&lt;li&gt;If current_sum becomes negative → reset to 0
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
python
def kadane(arr):
    current_sum = 0
    max_sum = float('-inf')

    for num in arr:
        current_sum += num
        max_sum = max(max_sum, current_sum)

        if current_sum &amp;lt; 0:
            current_sum = 0

    return max_sum

# Example
arr = [2, 3, -8, 7, -1, 2, 3]
print("Maximum Subarray Sum:", kadane(arr))


## Input
[2, 3, -8, 7, -1, 2, 3]

## output
11

subarray: [7, -1, 2, 3]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>python</category>
      <category>dsa</category>
      <category>arrays</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>First and Last Occurences</title>
      <dc:creator>Dharani </dc:creator>
      <pubDate>Sun, 22 Mar 2026 05:23:46 +0000</pubDate>
      <link>https://dev.to/dharani_boominathan_b1e6b/first-and-last-occurences-1986</link>
      <guid>https://dev.to/dharani_boominathan_b1e6b/first-and-last-occurences-1986</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Finding the first and last occurrences of an element is a common problem in arrays. It is especially useful in searching and indexing tasks.&lt;/p&gt;




&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;p&gt;Given a sorted array and a target value, find the first and last position of the target element.&lt;br&gt;&lt;br&gt;
If the element is not found, return [-1, -1].&lt;/p&gt;




&lt;h2&gt;
  
  
  Approach (Binary Search)
&lt;/h2&gt;

&lt;p&gt;We use Binary Search twice:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First Binary Search → to find the first occurrence
&lt;/li&gt;
&lt;li&gt;Second Binary Search → to find the last occurrence
&lt;/li&gt;
&lt;/ol&gt;




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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
python
def first_occurrence(arr, target):
    left, right = 0, len(arr) - 1
    result = -1

    while left &amp;lt;= right:
        mid = (left + right) // 2

        if arr[mid] == target:
            result = mid
            right = mid - 1   # search left side
        elif arr[mid] &amp;lt; target:
            left = mid + 1
        else:
            right = mid - 1

    return result


def last_occurrence(arr, target):
    left, right = 0, len(arr) - 1
    result = -1

    while left &amp;lt;= right:
        mid = (left + right) // 2

        if arr[mid] == target:
            result = mid
            left = mid + 1   # search right side
        elif arr[mid] &amp;lt; target:
            left = mid + 1
        else:
            right = mid - 1

    return result


def search_range(arr, target):
    return [first_occurrence(arr, target),
            last_occurrence(arr, target)]

# Example
arr = [5, 7, 7, 8, 8, 10]
target = 8
print("Positions:", search_range(arr, target))


## Input
 arr = [5, 7, 7, 8, 8, 10]
target = 8

## output
[3,4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>python</category>
      <category>dsa</category>
      <category>binarysearch</category>
      <category>arrays</category>
    </item>
    <item>
      <title>Sort 0s, 1s, 2s</title>
      <dc:creator>Dharani </dc:creator>
      <pubDate>Sun, 22 Mar 2026 05:20:03 +0000</pubDate>
      <link>https://dev.to/dharani_boominathan_b1e6b/sort-0s-1s-2s-58ll</link>
      <guid>https://dev.to/dharani_boominathan_b1e6b/sort-0s-1s-2s-58ll</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Sorting an array containing only 0s, 1s, and 2s is a common problem in data structures. It is also known as the Dutch National Flag problem.&lt;/p&gt;




&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;p&gt;Given an array containing only 0s, 1s, and 2s, sort the array in ascending order without using extra space.&lt;/p&gt;




&lt;h2&gt;
  
  
  Approach (Dutch National Flag Algorithm)
&lt;/h2&gt;

&lt;p&gt;We use three pointers:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;low → for 0s
&lt;/li&gt;
&lt;li&gt;mid → for traversal
&lt;/li&gt;
&lt;li&gt;high → for 2s
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Steps:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;If element is 0 → swap with low and move both low and mid
&lt;/li&gt;
&lt;li&gt;If element is 1 → move mid
&lt;/li&gt;
&lt;li&gt;If element is 2 → swap with high and move high
&lt;/li&gt;
&lt;/ul&gt;




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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
python
def sort_colors(arr):
    low = 0
    mid = 0
    high = len(arr) - 1

    while mid &amp;lt;= high:
        if arr[mid] == 0:
            arr[low], arr[mid] = arr[mid], arr[low]
            low += 1
            mid += 1

        elif arr[mid] == 1:
            mid += 1

        else:  # arr[mid] == 2
            arr[mid], arr[high] = arr[high], arr[mid]
            high -= 1

    return arr

# Example
arr = [2, 0, 2, 1, 1, 0]
print("Sorted Array:", sort_colors(arr))


## Input
 [2, 0, 2, 1, 1, 0]

## output
 [0, 0, 1, 1, 2, 2]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>python</category>
      <category>dsa</category>
      <category>arrays</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Find The Majority Element</title>
      <dc:creator>Dharani </dc:creator>
      <pubDate>Sun, 22 Mar 2026 05:17:05 +0000</pubDate>
      <link>https://dev.to/dharani_boominathan_b1e6b/find-the-majority-element-49ba</link>
      <guid>https://dev.to/dharani_boominathan_b1e6b/find-the-majority-element-49ba</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Finding the majority element is a common problem in data structures. It helps in understanding arrays, counting techniques, and efficient algorithms.&lt;/p&gt;




&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;p&gt;Given an array of size &lt;code&gt;n&lt;/code&gt;, find the element that appears more than ⌊n/2⌋ times.&lt;br&gt;&lt;br&gt;
You can assume that the majority element always exists.&lt;/p&gt;




&lt;h2&gt;
  
  
  Approach 1: Brute Force
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Count frequency of each element
&lt;/li&gt;
&lt;li&gt;Return the element with count &amp;gt; n/2
&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Python Code (Brute Force)&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
python
def majority_element(arr):
    n = len(arr)
    for i in arr:
        if arr.count(i) &amp;gt; n // 2:
            return i


## Input
   [2,2,1,1,2]

## output
   [2]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>python</category>
      <category>dsa</category>
      <category>arrays</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Squares Of a Sorted Array</title>
      <dc:creator>Dharani </dc:creator>
      <pubDate>Sun, 22 Mar 2026 05:14:17 +0000</pubDate>
      <link>https://dev.to/dharani_boominathan_b1e6b/squares-of-a-sorted-array-3i66</link>
      <guid>https://dev.to/dharani_boominathan_b1e6b/squares-of-a-sorted-array-3i66</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;The "Squares of a Sorted Array" problem is a common question that helps us understand arrays and the two-pointer technique.&lt;/p&gt;




&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;p&gt;Given a sorted array of integers (which may include negative numbers), return a new array of the squares of each number, also sorted in non-decreasing order.&lt;/p&gt;




&lt;h2&gt;
  
  
  Approach (Two-Pointer Technique)
&lt;/h2&gt;

&lt;p&gt;Since negative numbers become positive after squaring, we use two pointers:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Initialize:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;left = 0
&lt;/li&gt;
&lt;li&gt;right = n - 1
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Compare squares of left and right elements  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Place the larger square at the end of result array  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Move the corresponding pointer  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Repeat until all elements are processed  &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
python
def sorted_squares(nums):
    n = len(nums)
    result = [0] * n

    left, right = 0, n - 1
    pos = n - 1

    while left &amp;lt;= right:
        if abs(nums[left]) &amp;gt; abs(nums[right]):
            result[pos] = nums[left] ** 2
            left += 1
        else:
            result[pos] = nums[right] ** 2
            right -= 1
        pos -= 1

    return result

# Example
nums = [-4, -1, 0, 3, 10]
print("Sorted Squares:", sorted_squares(nums))


## Input
  [-4, -1, 0, 3, 10]

## Output
   [0, 1, 9, 16, 100]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>python</category>
      <category>dsa</category>
      <category>arrays</category>
      <category>twopointers</category>
    </item>
    <item>
      <title>Sort a Linked List Using Merge Sort</title>
      <dc:creator>Dharani </dc:creator>
      <pubDate>Sun, 22 Mar 2026 05:10:36 +0000</pubDate>
      <link>https://dev.to/dharani_boominathan_b1e6b/sort-a-linked-list-using-merge-sort-30h0</link>
      <guid>https://dev.to/dharani_boominathan_b1e6b/sort-a-linked-list-using-merge-sort-30h0</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Sorting a linked list efficiently is an important problem in data structures. Merge Sort is the best choice for linked lists because it does not require random access like arrays.&lt;/p&gt;




&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;p&gt;Given the head of a linked list, sort the list in ascending order using Merge Sort.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Merge Sort for Linked List?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Works efficiently on linked lists
&lt;/li&gt;
&lt;li&gt;Time Complexity: O(n log n)
&lt;/li&gt;
&lt;li&gt;Does not require extra space for shifting elements
&lt;/li&gt;
&lt;/ul&gt;




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

&lt;p&gt;We use Divide and Conquer:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Find the middle of the linked list
&lt;/li&gt;
&lt;li&gt;Divide the list into two halves
&lt;/li&gt;
&lt;li&gt;Recursively sort both halves
&lt;/li&gt;
&lt;li&gt;Merge the sorted halves
&lt;/li&gt;
&lt;/ol&gt;




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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
python
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

# Function to find middle of linked list
def get_middle(head):
    slow = head
    fast = head.next

    while fast and fast.next:
        slow = slow.next
        fast = fast.next.next

    return slow

# Function to merge two sorted lists
def merge(l1, l2):
    dummy = ListNode()
    tail = dummy

    while l1 and l2:
        if l1.val &amp;lt; l2.val:
            tail.next = l1
            l1 = l1.next
        else:
            tail.next = l2
            l2 = l2.next
        tail = tail.next

    tail.next = l1 if l1 else l2
    return dummy.next

# Merge Sort function
def merge_sort(head):
    if not head or not head.next:
        return head

    mid = get_middle(head)
    right = mid.next
    mid.next = None

    left = merge_sort(head)
    right = merge_sort(right)

    return merge(left, right)

## Input
   4-&amp;gt; 2-&amp;gt; 1-&amp;gt; 3

## output
   1 -&amp;gt; 2 -&amp;gt; 3 -&amp;gt; 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>python</category>
      <category>linkedlist</category>
      <category>dsa</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Reverse a Linked List</title>
      <dc:creator>Dharani </dc:creator>
      <pubDate>Sun, 22 Mar 2026 05:06:44 +0000</pubDate>
      <link>https://dev.to/dharani_boominathan_b1e6b/reverse-a-linked-list-2ee5</link>
      <guid>https://dev.to/dharani_boominathan_b1e6b/reverse-a-linked-list-2ee5</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Reversing a linked list is one of the most common problems in data structures. It helps in understanding pointers and linked list traversal.&lt;/p&gt;




&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;p&gt;Given the head of a singly linked list, reverse the list and return the new head.&lt;/p&gt;




&lt;h2&gt;
  
  
  Approach (Iterative Method)
&lt;/h2&gt;

&lt;p&gt;We can reverse the linked list using three pointers:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Initialize:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;prev = None
&lt;/li&gt;
&lt;li&gt;current = head
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Traverse the list:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Store next node
&lt;/li&gt;
&lt;li&gt;Reverse the link
&lt;/li&gt;
&lt;li&gt;Move prev and current forward
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Continue until current becomes None  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Return prev as new head  &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
python
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

def reverseList(head):
    prev = None
    current = head

    while current:
        next_node = current.next   
        current.next = prev        
        prev = current             
        current = next_node        

    return prev


## Input
    1 -&amp;gt; 2 -&amp;gt; 3 -&amp;gt; 4 -&amp;gt; 5

## ouput
   5-&amp;gt; 4-&amp;gt; 3-&amp;gt; 2-&amp;gt; 1



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

&lt;/div&gt;

</description>
      <category>python</category>
      <category>linkedlist</category>
      <category>dsa</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Kadanes Algorithm</title>
      <dc:creator>Dharani </dc:creator>
      <pubDate>Sun, 22 Mar 2026 05:03:13 +0000</pubDate>
      <link>https://dev.to/dharani_boominathan_b1e6b/kadanes-algorithm-26ha</link>
      <guid>https://dev.to/dharani_boominathan_b1e6b/kadanes-algorithm-26ha</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Kadane’s Algorithm is an efficient way to find the maximum sum of a contiguous subarray. It is widely used in array and dynamic programming problems.&lt;/p&gt;




&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;p&gt;Given an array of integers (both positive and negative), find the contiguous subarray with the maximum sum and return that sum.&lt;/p&gt;




&lt;h2&gt;
  
  
  Approach (Kadane’s Algorithm)
&lt;/h2&gt;

&lt;p&gt;We use a dynamic approach:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Initialize two variables:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;current_sum = 0
&lt;/li&gt;
&lt;li&gt;max_sum = very small number
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Traverse the array:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add current element to current_sum
&lt;/li&gt;
&lt;li&gt;If current_sum becomes greater than max_sum → update max_sum
&lt;/li&gt;
&lt;li&gt;If current_sum becomes negative → reset it to 0
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
python
def max_subarray_sum(arr):
    current_sum = 0
    max_sum = float('-inf')

    for num in arr:
        current_sum += num
        max_sum = max(max_sum, current_sum)

        if current_sum &amp;lt; 0:
            current_sum = 0

    return max_sum

# Example
arr = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
print("Maximum Subarray Sum:", max_subarray_sum(arr))


## Input
  [-2, 1, -3, 4, -1, 2, 1, -5, 4]

## Output
   6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>python</category>
      <category>dsa</category>
      <category>arrays</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Move Zeros</title>
      <dc:creator>Dharani </dc:creator>
      <pubDate>Sun, 22 Mar 2026 04:58:49 +0000</pubDate>
      <link>https://dev.to/dharani_boominathan_b1e6b/move-zeros-53f5</link>
      <guid>https://dev.to/dharani_boominathan_b1e6b/move-zeros-53f5</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Moving zeros in an array is a common problem that helps in understanding array manipulation and two-pointer techniques.&lt;/p&gt;




&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;p&gt;Given an array, move all zeros to the end while maintaining the relative order of non-zero elements.&lt;/p&gt;




&lt;h2&gt;
  
  
  Approach (Two-Pointer Technique)
&lt;/h2&gt;

&lt;p&gt;We use two pointers:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Initialize a pointer &lt;code&gt;j = 0&lt;/code&gt; (position for non-zero elements)
&lt;/li&gt;
&lt;li&gt;Traverse the array using index &lt;code&gt;i&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;If element is non-zero:

&lt;ul&gt;
&lt;li&gt;Swap arr[i] with arr[j]
&lt;/li&gt;
&lt;li&gt;Increment j
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Continue until the end
&lt;/li&gt;
&lt;/ol&gt;




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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
python
def move_zeros(arr):
    j = 0

    for i in range(len(arr)):
        if arr[i] != 0:
            arr[i], arr[j] = arr[j], arr[i]
            j += 1

    return arr

# Example
arr = [0, 1, 0, 3, 12]
print("Result:", move_zeros(arr))


## Input
 [0,1,0,3,4]

## Output
 [1,3,4,0,0]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>python</category>
      <category>arrays</category>
      <category>dsa</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
