Articles on Trending Technologies

Technical articles with clear explanations and examples

Last Stone Weight in Python

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

The Last Stone Weight problem simulates repeatedly smashing the two heaviest stones together until at most one stone remains. When two stones with weights x and y collide (where x ≤ y), they either both get destroyed if equal, or the lighter stone is destroyed and the heavier one becomes y - x. Problem Rules If x = y, then both stones are totally destroyed If x ≠ y, the stone of weight x is destroyed, and the stone of weight y becomes y - x For example, with stones [2, 7, 4, 1, 8, ...

Read More

Partition Array Into Three Parts With Equal Sum in Python

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

Given an array of integers, we need to determine if we can partition it into three non-empty parts with equal sums. This means finding two partition points that divide the array into three contiguous subarrays where each subarray has the same sum. Formally, we need to find indices i and j where i+1 < j such that: Sum of elements from index 0 to i equals Sum of elements from index i+1 to j-1 equals Sum of elements from index j to end For example, with input [0, 2, 1, -6, 6, -7, 9, 1, ...

Read More

Pairs of Songs With Total Durations Divisible by 60 in Python

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

Finding pairs of songs with total durations divisible by 60 is a common algorithmic problem. We can solve this efficiently using the remainder approach with a hash map to track remainders when dividing by 60. Problem Understanding Given a list of song durations, we need to count pairs where the sum is divisible by 60. For example, with [30, 20, 150, 100, 40], we get 3 pairs: (30, 150), (20, 100), and (20, 40) since 180, 120, and 60 are all divisible by 60. Algorithm Approach The key insight is using modular arithmetic: Two ...

Read More

Sum of Even Numbers After Queries in Python

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

Given an array of integers A and a list of queries, we need to process each query and calculate the sum of even numbers after each modification. For the i-th query, value = queries[i][0] and index = queries[i][1], we add the value to A[index] and then find the sum of all even values in the updated array. Problem Understanding Let's understand with an example. If the array is [1, 2, 3, 4] and queries are [[1, 0], [-3, 1], [-4, 0], [2, 3]]: Initial array: [1, 2, 3, 4], sum of even numbers: 2 + 4 ...

Read More

Jewels and Stones in Python

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

The Jewels and Stones problem is a classic programming challenge where we need to count how many stones are actually jewels. Given a string J representing jewel types and string S representing stones, we count how many characters in S appear in J. The comparison is case-sensitive. For example, if J = "aZc" and S = "catTableZebraPicnic", we need to count occurrences of 'a', 'Z', and 'c' in the stones string. Method 1: Using Dictionary (Hash Set) Create a dictionary to store jewel types for O(1) lookup, then iterate through stones ? class Solution: ...

Read More

Array Partition I in Python

Sunidhi Bansal
Sunidhi Bansal
Updated on 25-Mar-2026 2K+ Views

Given an array of 2n integers, we need to group them into n pairs such that the sum of minimum values from each pair is maximized. This is known as the Array Partition I problem. Problem Understanding For an array like [1, 2, 3, 4], we can form pairs in different ways ? (1, 2) and (3, 4) → min(1, 2) + min(3, 4) = 1 + 3 = 4 (1, 4) and (2, 3) → min(1, 4) + min(2, 3) = 1 + 2 = 3 (1, 3) and (2, 4) → min(1, 3) + ...

Read More

Diameter of Binary Tree in Python

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

The diameter of a binary tree is the length of the longest path between any two nodes in the tree. This path may or may not pass through the root node. We can solve this problem using depth-first search (DFS) to calculate the height of each subtree and track the maximum diameter found. 1 2 3 4 5 ...

Read More

Intersection of Two Arrays II in Python

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

Finding the intersection of two arrays means identifying common elements between them, preserving duplicates based on their frequency in both arrays. For example, if A = [1, 4, 5, 3, 6] and B = [2, 3, 5, 7, 9], the intersection will be [3, 5]. Algorithm Steps To solve this problem efficiently, we follow these steps: Take two arrays A and B If length of A is smaller than length of B, swap them for optimization Calculate the frequency of elements in the larger ...

Read More

First Bad Version in Python

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

In software development, when a version fails quality checks, all subsequent versions are also considered bad since they're built upon the faulty version. The First Bad Version problem asks us to find the earliest bad version efficiently using binary search. We have versions numbered from 1 to n, and an API function isBadVersion(version) that returns True if the version is bad, False otherwise. Our goal is to find the first bad version with minimum API calls. Algorithm Overview We use binary search to efficiently locate the first bad version ? If n < 2, return ...

Read More

Lowest Common Ancestor of a Binary Search Tree in Python

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

The Lowest Common Ancestor (LCA) of two nodes in a binary tree is the lowest node that has both nodes as descendants. In a binary search tree, we can use the BST property to find the LCA efficiently. 6 2 8 0 4 7 9 ...

Read More
Showing 1–10 of 61,304 articles
« Prev 1 2 3 4 5 6131 Next »
Advertisements