Server Side Programming Articles

Page 579 of 2109

Intersection of Two Linked Lists in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 1K+ Views

When two linked lists share common nodes, we need to find their intersection point. The intersection occurs where both lists reference the same node object, not just nodes with the same value. Given two linked lists A and B, we return the reference to the first common node. If there's no intersection, we return None. Algorithm We use a hash map to track visited nodes from the first list, then check if any node from the second list exists in our map ? Create a dictionary to store nodes from list A Traverse list A ...

Read More

Min Stack in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 3K+ Views

A Min Stack is a special data structure that supports all standard stack operations (push, pop, top) plus retrieving the minimum element in constant O(1) time. This is achieved by storing the previous minimum value alongside each new minimum. Algorithm The key insight is to store the previous minimum when pushing a new minimum value ? Initialize the stack with min element as infinity For push(x): if x ≤ current min, store the old min in stack first, then update min to x For pop(): if popped element equals current min, restore the previous min from ...

Read More

Linked List Cycle in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 2K+ Views

A linked list cycle occurs when a node in the linked list points back to a previous node, creating a loop. To detect cycles, we can use a hash set to track visited nodes or implement Floyd's cycle detection algorithm (tortoise and hare). The cycle is represented by a pos parameter indicating where the tail connects. If pos = -1, no cycle exists. For example, in the list [5, 3, 2, 0, -4, 7] with pos = 1, the tail connects to the second node (index 1), creating a cycle. Using Hash Set Approach This method tracks ...

Read More

Hamming Distance in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 4K+ Views

The Hamming distance between two integers is the number of positions where the corresponding bits differ. For example, if we have numbers 7 and 15, they are 0111 and 1111 in binary respectively. Only the most significant bit differs, so the Hamming distance is 1. Algorithm Steps To calculate the Hamming distance, we follow these steps ? Iterate through each bit position from 31 down to 0 Extract the bit at position i for both numbers using right shift and bitwise AND Compare the bits ? if they differ, increment the distance counter Return the total ...

Read More

Fizz Buzz in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 4K+ Views

The Fizz Buzz problem is a classic programming challenge where we replace numbers with specific strings based on divisibility rules. For numbers from 1 to n, we print "Fizz" for multiples of 3, "Buzz" for multiples of 5, and "FizzBuzz" for multiples of both. Problem Rules If the number is divisible by 3, write "Fizz" instead of the number If the number is divisible by 5, write "Buzz" instead of the number If the number is divisible by both 3 and 5, write "FizzBuzz" instead ...

Read More

Move Zeroes in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 1K+ Views

Sometimes we need to move all zero values in an array to the right while maintaining the relative order of non-zero elements. For example, transforming [0, 1, 5, 0, 3, 8, 0, 0, 9] into [1, 5, 3, 8, 9, 0, 0, 0, 0]. Algorithm Approach We use a two-pointer technique to solve this problem efficiently ? Use an insert_index pointer to track where to place the next non-zero element Iterate through the array and move non-zero elements to the front Fill remaining positions ...

Read More

Missing Number in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 539 Views

Suppose we have a list of numbers from 0 to n. There is one number that is missing. We have to find the missing number in an efficient approach. So if A = [0, 1, 2, 3, 4, 5, 7, 8, 9], missing number is 6. Python provides multiple approaches to solve this problem efficiently. We'll explore three common methods: binary search, mathematical formula, and XOR operation. Method 1: Using Binary Search The binary search approach works by comparing array values with their indices after sorting ? Sort the list in ascending order Set high ...

Read More

Valid Anagram in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 746 Views

Anagrams are words or phrases formed by rearranging the letters of another word or phrase, using all the original letters exactly once. For example, "ANAGRAM" and "NAAGARM" are anagrams because they contain the same letters in different arrangements, but "cat" and "fat" are not anagrams because they have different letters. To check if two strings are valid anagrams, we can use several approaches. The most common method is to sort the characters of both strings and compare them. Method 1: Using Sorting Convert both strings to sorted character lists and compare them ? def is_anagram_sorting(s, ...

Read More

Delete Node in a Linked List in Python

sudhir sharma
sudhir sharma
Updated on 25-Mar-2026 4K+ Views

A linked list is a linear data structure where each element is a separate object, commonly referred to as a node. Each node contains two fields: the data and a pointer to the next node in the list. In this article, we'll learn how to delete a node from a singly linked list using Python. Suppose we have a linked list with a few elements. Our task is to delete a specific node, given only access to that node − not the head of the list ? Input: 1 → 3 → 5 → 7 → ...

Read More

Invert Binary Tree in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 1K+ Views

Inverting a binary tree means swapping the left and right child nodes for every node in the tree. This creates a mirror image of the original tree structure. Original Tree 4 2 7 1 3 6 ...

Read More
Showing 5781–5790 of 21,090 articles
« Prev 1 577 578 579 580 581 2109 Next »
Advertisements