Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 146 of 377

Kth Largest Element in a Stream in Python

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

The Kth Largest Element in a Stream problem involves designing a class that efficiently finds the kth largest element as new elements are added to a data stream. This is particularly useful in real-time data processing scenarios. The KthLargest class maintains a stream of numbers and returns the kth largest element each time a new number is added. Note that we want the kth largest in sorted order, not the kth distinct element. Problem Understanding Given k = 3 and initial elements [4, 5, 8, 2], when we add elements 3, 5, 10, 9, 4 sequentially, we ...

Read More

Employee Importance in Python

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

The employee importance problem calculates the total importance value of an employee and all their subordinates. Each employee has three attributes: a unique ID, importance value, and list of direct subordinate IDs. Problem Understanding Given a company's employee data structure, we need to find the cumulative importance of a specific employee including all subordinates in their hierarchy. For example, if employee 1 leads employees 2 and 3, the total importance is the sum of all three employees' individual importance values. Algorithm Steps We'll solve this using a breadth-first search approach ? Create dictionaries to ...

Read More

Baseball Game in Python

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

A baseball game point recorder tracks scores using operations on a stack. We have a list of strings where each string represents either a score or an operation that modifies previous scores. Game Rules The four types of operations are ? Integer − Indicates the number of points scored in this round "+" − Points are the sum of the last two valid rounds "D" − Points are double the last valid round's points "C" − Cancel the last valid ...

Read More

Construct String from Binary Tree in Python

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

Constructing a string representation of a binary tree using parentheses helps visualize tree structure. This approach uses preorder traversal where null nodes are represented by empty parenthesis pairs (), and unnecessary empty pairs are omitted to maintain one-to-one mapping. Problem Overview Given a binary tree, we need to construct a string with parentheses and integers using preorder traversal. The rules are ? Each node's value is followed by its children in parentheses Null nodes are represented as empty parentheses () Omit empty parentheses that don't affect the tree structure If a node has no children, no ...

Read More

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 412 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 258 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

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 376 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 386 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
Showing 1451–1460 of 3,768 articles
« Prev 1 144 145 146 147 148 377 Next »
Advertisements