Server Side Programming Articles

Page 555 of 2109

Prime Number of Set Bits in Binary Representation in Python

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

Suppose we have two integers L and R, we have to find the count of numbers in the range [L, R] (inclusive) having a prime number of set bits in their binary form. So, if the input is like L = 6 and R = 10, then the output will be 4, as there are 4 numbers 6(110), 7(111), 9(1001), 10(1010), all have prime number of set bits. Understanding Set Bits Set bits are the bits that are '1' in the binary representation of a number. For example: 6 in binary is 110, which has ...

Read More

Shortest Completing Word in Python

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

The Shortest Completing Word problem requires finding the shortest word from a dictionary that contains all letters from a given license plate. The word must include each letter at least as many times as it appears in the license plate, ignoring case and non-alphabetic characters. For example, if the license plate is "PP", the word "pile" doesn't work because it only has one 'P', but "topper" works because it has two 'P's. Problem Understanding Given a license plate string and a list of words, we need to: Extract only alphabetic characters from the license plate ...

Read More

Largest Number At Least Twice of Others in Python

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

Given an integer array nums, we need to check whether the largest element is at least twice as large as every other number in the array. If it satisfies this condition, return the index of the largest element, otherwise return -1. So, if the input is like [3, 6, 1, 0], then the output will be 1, as 6 is the largest number, and for every other number in the array x, 6 is more than twice as big as x. Since the index of 6 is 1, the output is 1. Algorithm To solve this problem, ...

Read More

Min Cost Climbing Stairs in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 949 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 627 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 803 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 323 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
Showing 5541–5550 of 21,090 articles
« Prev 1 553 554 555 556 557 2109 Next »
Advertisements