Showing 26 questions
You are given a collection of intervals. Merge all overlapping intervals into a single interval and return the result.
#1. Merge Intervals
You're given a string and need to repeatedly remove adjacent, identical characters until no more duplicates exist. Return the final string after all such removals.
#2. Remove All Adjacent Duplicates In String
Design a data structure that supports insert, delete, and getRandom operations, all in average O(1) time. The getRandom method should return a random element from the current set of elements.
#3. Insert Delete GetRandom O(1)
Given a string, repeatedly remove consecutive duplicate characters if they appear k times in a row. The goal is to return the final string after all possible removals.
#4. Remove All Adjacent Duplicates in String II
Implement a spellchecker that corrects misspellings by considering both exact matches and variations where vowels may be incorrect or missing. Given a list of correctly spelled words (the wordlist) and a list of queries, return the corrected spelling for each query based on prioritized matching rules.
#5. Vowel Spellchecker
Find all the 10-letter long sequences that occur more than once in a given DNA molecule represented as a string. The DNA string contains only the characters 'A', 'C', 'G', and 'T'.
#6. Repeated DNA Sequences
You're given a sorted array that has been rotated, and a target value. Find the index of the target value in the rotated array, or return -1 if it's not present.
#7. Search in Rotated Sorted Array
Given a number 'n', generate all possible well-formed (balanced) parentheses strings of length 2*n. For instance, if n=3, you need to create all valid combinations like '((()))', '(()())', etc.
#8. Generate Parentheses
Determine if a positive integer is a perfect number. A perfect number equals the sum of its proper divisors (excluding the number itself).
#9. Perfect Number
You are climbing a staircase with n steps. Find how many distinct ways you can climb to the top, given that you can climb one or two steps at a time.
#10. Climbing Stairs
Calculate the integer square root of a non-negative integer, truncating any decimal portion. Return the integer part of the square root.
#11. Sqrt(x)
Determine if a given word can be constructed from letters in a 2D board, where letters can be used horizontally or vertically. Each letter can only be used once in the word.
#12. Word Search
Given a grid representing land and water, count the number of distinct islands. An island is formed by connected land cells.
#13. Number of Islands
Simulate backspace operations on two strings and determine if the resulting strings are equal. Effectively, you need to compare strings after processing backspace characters.
#14. Backspace String Compare
Given a string and a dictionary of words, find all possible ways to break the string into space-separated words from the dictionary. Return the list of these valid sentences.
#15. Word Break II
Find the sum of all the left leaves in a given binary tree. A left leaf is a node that is both a leaf and the left child of its parent.
#16. Sum of Left Leaves
Design a data structure that efficiently stores a set of strings and allows for prefix-based searches. Implement methods to insert strings, search for complete words, and check if any word starts with a given prefix.
#17. Implement Trie (Prefix Tree)
Design a logger that prevents duplicate messages from being printed within a certain time window. Determine if a message should be printed based on its timestamp and content, considering rate limiting.
#18. Logger Rate Limiter
Determine if a given string can be segmented into a space-separated sequence of words from a dictionary. You are given a string and a dictionary of words; can you break the string down using words from the dictionary?
#19. Word Break
You're given a ciphertext that was encoded diagonally. Figure out how it was encoded and decode the message to reveal the original text.
#20. Decode the Slanted Ciphertext