Programming Articles

Page 559 of 2547

Min Cost Climbing Stairs in Python

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

The min cost climbing stairs problem is a classic dynamic programming challenge. Given a staircase where each step has a cost, we need to find the minimum cost to reach the top. We can start from either step 0 or step 1, and from any step we can climb either one or two steps forward. For example, if we have cost = [12, 17, 20], the minimum cost is 17. We start from step 1 (cost 17) and climb two steps to reach the top, avoiding the higher costs of steps 0 and 2. Algorithm Steps We ...

Read More

Find Smallest Letter Greater Than Target in Python

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

Given a sorted list of lowercase letters, we need to find the smallest letter that is greater than a target letter. The letters wrap around, so if no letter is greater than the target, we return the first letter in the list. For example, if we have letters ["c", "f", "j"] and target "a", the answer is "c". If the target is "z" and letters are ["a", "b"], the answer wraps around to "a". Using Binary Search Since the letters are already sorted, we can use binary search to find the smallest letter greater than the target ...

Read More

Longest Word in Dictionary in Python

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

Finding the longest word in a dictionary that can be built one character at a time is a classic problem that can be solved efficiently using a Trie (Prefix Tree) data structure. The goal is to find the longest word where each prefix also exists in the dictionary. For example, given the dictionary ["h", "he", "hel", "hell", "hello"], the word "hello" can be built step by step since "h", "he", "hel", and "hell" all exist in the dictionary. Algorithm Overview The solution uses a Trie to store all words and then checks if each word can be ...

Read More

1-bit and 2-bit Characters in Python

Sarika Singh
Sarika Singh
Updated on 25-Mar-2026 802 Views

In computers, everything is stored in the form of bits, i.e., the smallest pieces of data that can be either 0 or 1. When we talk about 1-bit or 2-bit characters, we mean how many of these bits are used to make a single character (like a letter or symbol). A 1-bit character is just a single 0. It counts as one character by itself. A 2-bit character is made of two bits and can be either 10 or 11. If we are given a list of bits (containing only 0s and 1s) that ends with ...

Read More

Design HashMap in Python

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

A HashMap is a key-value data structure that provides fast lookups, insertions, and deletions. We can implement a custom HashMap in Python using an array of linked lists to handle collisions through chaining. HashMap Operations Our HashMap will support three main operations ? put(key, value) − Insert or update a key-value pair get(key) − Retrieve the value for a given key, return -1 if not found remove(key) − Delete a key-value pair from the HashMap Implementation Strategy We'll use separate chaining to handle hash collisions. Each bucket in our hash table contains a ...

Read More

Kth Largest Element in a Stream in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 638 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 321 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 927 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 375 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
Showing 5581–5590 of 25,466 articles
« Prev 1 557 558 559 560 561 2547 Next »
Advertisements