Showing 202 questions
You're managing a power grid and need to schedule maintenance. Determine the minimum number of maintenance periods required to ensure no two adjacent power lines are down simultaneously.
#1. Power Grid Maintenance
Find the minimum number of operations to reduce a given positive integer to 0. You can either subtract a power of 2 or add a power of 2 in each operation.
#2. Minimum Operations to Reduce an Integer to 0
Compress a given string by replacing consecutive repeating characters with the character followed by the count of repetitions. If the compressed string isn't shorter, return the original.
#3. String Compression
Design and implement a Least Frequently Used (LFU) cache. The cache should allow you to get and put key-value pairs, evicting the least frequently used key when the cache is full.
#4. LFU Cache
You're given a list of numbers. By deleting a number, you earn its value, but you must also delete all numbers one less and one greater than it. Maximize the total earned value.
#5. Delete and Earn
You're given a graph where each node has a value. Divide the graph into connected components to minimize the largest component's cost, where cost is the greatest common divisor of all node values in the component.
#6. Minimize Maximum Component Cost
Find the three numbers in a given array whose product is maximum. Return the maximum product possible from any three numbers in the array.
#7. Maximum Product of Three Numbers
The goal is to generate all possible full binary trees with a given number of nodes. Each node in the tree should have either 0 or 2 children.
#8. All Possible Full Binary Trees
Find the longest sequence of characters that appears in the same order in two given strings. The characters don't need to be consecutive, just in the same order.
#9. Longest Common Subsequence
Implement a search suggestion system. Given a search word and a list of product names, return the top 3 product suggestions after each character of the search word is typed.
#10. Search Suggestions System
Given an array and a series of queries, find the index of the element closest to the query index that has the same value as the element at the query index. Return -1 if no such element exists.
#11. Closest Equal Element Queries
Find the number of contiguous subarrays within a given array whose product is strictly less than a target value k. The goal is to efficiently count these subarrays by considering the product of their elements.
#12. Subarray Product Less Than K
Find the length of the smallest substring within a given string that contains only identical characters. If no such substring exists, return -1.
#13. Smallest Substring With Identical Characters I
Find the smallest substring within a given string that contains at least 'k' occurrences of a single character. Return the length of that substring, or -1 if no such substring exists.
#14. Smallest Substring With Identical Characters II
Given a string, repeatedly remove adjacent characters that are 'almost equal' (differ by one). Find the length of the resulting string after all possible removals.
#15. Remove Adjacent Almost-Equal Characters
Design a data structure that acts as a Least Recently Used (LRU) cache. Implement methods to get and put key-value pairs, evicting the least recently used entry when the cache is full.
#16. LRU Cache
Determine how many distinct subsequences of a string T exist within another string S. A subsequence is formed by deleting some (or none) of the characters from the original string.
#17. Distinct Subsequences
Find the substring that occurs the most within a given string, subject to length and character limit constraints. Return the maximum number of times this substring appears.
#18. Maximum Number of Occurrences of a Substring
Given a grid representing land and water, count the number of distinct islands. An island is formed by connected land cells.
#19. Number of Islands
Imagine you're watering a garden using strategically placed taps. Find the fewest taps you need to open to water the entire garden, given each tap's watering range.
#20. Minimum Number of Taps to Open to Water a Garden