Showing 31 questions
Given a string and two substrings, find the indices where the first substring occurs. Then, find the indices where the second substring occurs. Return the indices of the first substring that are close to any index of the second substring, within a specified range.
#1. Find Beautiful Indices in the Given Array I
You're given a string and a list of index pairs. You can swap characters at these indices any number of times. Find the lexicographically smallest string you can obtain after performing these swaps.
#2. Smallest String With Swaps
You're given a string and two patterns. Find all 'beautiful' indices where an occurrence of the first pattern is within 'k' distance of an occurrence of the second pattern.
#3. Find Beautiful Indices in the Given Array II
You are given a list of 24-hour clock times. Find the smallest difference in minutes between any two times in the list.
#4. Minimum Time Difference
Determine if there are any duplicate numbers in an array where the indices of these duplicates are within a certain distance of each other. Specifically, check if any two equal numbers exist in the array, where their indices differ by at most k.
#5. Contains Duplicate II
You're given an array of numbers and need to efficiently calculate the sum of values within specified ranges of indices in the array. The array itself will not change.
#6. Range Sum Query - Immutable
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.
#7. LRU Cache
Convert a non-negative integer into its English word representation. For example, 12345 should be converted to 'Twelve Thousand Three Hundred Forty Five'.
#8. Integer to English Words
Find the unique number in an array where every other number appears exactly twice. Your task is to efficiently identify this single, non-repeating element.
#9. Single Number
Determine if a set of points forms a perfect straight line. You're given the coordinates of several points; check if they all lie on the same line.
#10. Check If It Is a Straight Line
You're given a rectangular piece of wood and prices for different sized pieces you can sell. Determine the maximum profit you can make by cutting the wood into smaller pieces and selling them.
#11. Selling Pieces of Wood
Find the maximum length of a contiguous subarray that sums to a given target value k. You need to return the length of the longest such subarray.
#12. Maximum Size Subarray Sum Equals k
Given an array, determine if there are any two distinct elements within a certain distance of each other that have an absolute difference less than or equal to a given threshold. Consider both index and value differences.
#13. Contains Duplicate III
Determine if any value appears at least twice in an array of numbers. Return true if duplicates exist; otherwise, return false.
#14. Contains Duplicate
You are given k sorted lists. Combine all of their elements into a single sorted list and return it.
#15. Merge k Sorted Lists
You are given a collection of intervals. Merge all overlapping intervals into a single interval and return the result.
#16. Merge Intervals
Find the shortest distance between two occurrences of a word within a list of words. The two words can be the same.
#17. Shortest Word Distance III
You're given a square grid of values. Build a quadtree to represent this grid, recursively dividing into quadrants based on whether the values within each quadrant are all the same.
#18. Construct Quad Tree
You are given a list of accounts where each account has a name and a list of email addresses. Your task is to merge accounts belonging to the same person based on shared email addresses.
#19. Accounts Merge
Determine how many subsequences of a given binary string satisfy a specific condition based on the number of set bits. You need to count only the subsequences whose decimal value equals a power of 2.
#20. Count the Number of Good Subsequences