Programming Articles

Page 124 of 2547

Heaters in Python

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

The heater radius problem is a classic optimization challenge where we need to find the minimum radius for heaters to warm all houses on a horizontal line. Given positions of houses and heaters, we calculate the smallest radius that ensures every house is within range of at least one heater. For example, with houses at positions [1, 2, 3, 4] and heaters at [1, 4], the minimum radius is 1. House at position 1 is covered by heater at position 1, houses at positions 2 and 3 are covered by either heater (within radius 1), and house at position ...

Read More

Number of Boomerangs in Python

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

A boomerang in computational geometry is a tuple of points (i, j, k) where the distance from point i to point j equals the distance from point i to point k. Given n distinct points in a plane, we need to count all possible boomerangs. For example, with points [[0, 0], [1, 0], [2, 0]], we can form boomerangs like [[1, 0], [0, 0], [2, 0]] and [[1, 0], [2, 0], [0, 0]] where point [1, 0] is equidistant from [0, 0] and [2, 0]. Algorithm The approach uses a distance-counting strategy ? For each ...

Read More

Remove Element in Python

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

Removing elements from a list is a common operation in Python. When we need to remove all instances of a specific value in-place and return the new length, we can use a two-pointer approach that modifies the original list efficiently. The problem: given a list nums and a value val, remove all instances of val in-place and return the new length of the modified list. Algorithm Steps To solve this problem, we follow these steps ? Initialize count = 0 (tracks position for valid elements) For each ...

Read More

Difference between IPv4 and IPv6

Kiran Kumar Panigrahi
Kiran Kumar Panigrahi
Updated on 25-Mar-2026 9K+ Views

IPv4 and IPv6 are internet protocol versions, with IPv6 being an upgraded version of IPv4. There are several differences between the IPv4 and IPv6 protocols, including their functionality, but the most important difference is the quantity of addresses (Address space) that they create. Read through this article to find out more about IPv4 and IPv6 and how they are different from each other. What is Internet Protocol (IP)? The Internet Protocol is a set of rules that allows our computers to communicate via the Internet. IP addresses are basically in charge of directing the data packets to ...

Read More

Integer to English Words in Python Programming

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

Converting integers to their English word representation is a common programming challenge. In Python, we can solve this by breaking down numbers into groups of three digits and converting each group separately using predefined word mappings. Approach To convert a number to English words, we follow these steps: Create arrays for numbers less than 20, tens (20, 30, 40, etc.), and scale words (thousand, million, billion) Use a helper function to convert numbers less than 1000 to words Process the number in groups of three digits from right to left Combine the converted groups with appropriate ...

Read More

Longest Chunked Palindrome Decomposition in python

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

The Longest Chunked Palindrome Decomposition problem asks us to find the maximum number of chunks we can split a string into, where the chunks form a palindromic pattern. This means the first chunk equals the last chunk, the second equals the second-to-last, and so on. For example, given the string "antaprezatepzapreanta", we can decompose it as "(a)(nt)(a)(pre)(za)(tpe)(za)(pre)(a)(nt)(a)" which gives us 11 chunks in palindromic order. Algorithm The approach uses two pointers moving from both ends toward the center ? Use two pointers: start at the beginning and end at the end Build chunks from both ...

Read More

Smallest Sufficient Team in Pyhton

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

The Smallest Sufficient Team problem asks us to find the minimum number of people needed to cover all required skills for a project. Given a list of required skills and people with their respective skills, we need to select the smallest team that collectively possesses all required skills. Problem Understanding A sufficient team is a set of people where every required skill is covered by at least one team member. We represent teams using indices − for example, team [0, 2] means people at positions 0 and 2 in the people array. Algorithm Approach We use ...

Read More

Parsing A Boolean Expression in Python

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

Boolean expression parsing involves evaluating complex logical expressions containing AND, OR, and NOT operations. Python can parse these expressions recursively by breaking them down into smaller components. Boolean Expression Format A boolean expression can be one of the following ? "t" − evaluates to True "f" − evaluates to False "!(expression)" − logical NOT of the inner expression "&(expr1, expr2, ...)" − logical AND of 2 or more expressions "|(expr1, expr2, ...)" − logical OR of 2 or more expressions Algorithm Approach We'll use a recursive approach with the following steps ? ...

Read More

Escape a Large Maze Python

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

In this problem, we need to determine if it's possible to navigate from a source position to a target position in a massive 1 million × 1 million grid while avoiding blocked cells. The key insight is that we can't perform a full BFS/DFS on such a large grid, so we use a clever optimization. Problem Analysis The main challenge is the grid size − searching 1 million × 1 million cells would be too slow. However, if there are only a small number of blocked cells, they can only create a limited "enclosed area". The maximum area ...

Read More

Grid Illumination in Python

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

Grid illumination is a problem where we have an N x N grid with lamps at specific positions. Each lamp illuminates its entire row, column, and both diagonals. We need to answer queries about whether specific cells are illuminated, then turn off lamps in the queried cell and its 8 adjacent neighbors. Problem Understanding Given an N x N grid with lamps at positions specified in the lamps array, each lamp illuminates ? Its entire row (x-axis) Its entire column (y-axis) Both diagonals passing through it For each query (x, y), we check if ...

Read More
Showing 1231–1240 of 25,469 articles
« Prev 1 122 123 124 125 126 2547 Next »
Advertisements