Showing 28 questions
You are given a list of paths, where each path connects two cities. Find the destination city, which is the city that has a path coming in but no path going out.
#1. Destination City
You're given a list of restaurants with their vegan-friendly status, price, and distance. Select the restaurants that match specified vegan, price, and distance criteria and return their IDs in sorted order.
#2. Filter Restaurants by Vegan-Friendly, Price and Distance
Determine if it is possible to finish all courses given prerequisite relationships between them. Essentially, detect if a cycle exists in the course dependencies.
#3. Course Schedule
Find all the shortest transformation sequences from a start word to an end word, using a dictionary of valid words. You can only change one letter at a time.
#4. Word Ladder II
You're given two lists of strings representing favorite restaurants. Find the common strings with the minimum index sum across both lists.
#5. Minimum Index Sum of Two Lists
Determine if two strings are anagrams of each other, meaning they contain the same characters in a different order. You need to check if one string can be rearranged to form the other.
#6. Valid Anagram
Reverse the order of words in a given string. The input string may contain leading or trailing spaces, which should be removed in the output.
#7. Reverse Words in a String
Find the k most frequently occurring words in a given list of words. Return the top k words sorted by frequency, and then alphabetically for words with the same frequency.
#8. Top K Frequent Words
You are given a collection of intervals. Merge all overlapping intervals into a single interval and return the result.
#9. Merge Intervals
You are given the head of a singly linked list. Reverse the list and return the new head.
#10. Reverse Linked List
Transform one word into another, one letter at a time, using only words from a given dictionary. Find the shortest sequence of words to reach the target.
#11. Word Ladder
Design a data structure that supports insertion, deletion, and random element retrieval, all in constant time on average. You'll need to handle edge cases carefully to achieve O(1) complexity.
#12. Insert Delete GetRandom O(1)
Find the longest string that is a prefix of all strings in a given array. If no common prefix exists, return an empty string.
#13. Longest Common Prefix
Find the length of the longest substring within a given string that contains no repeating characters. The substring must be contiguous.
#14. Longest Substring Without Repeating Characters
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.
#15. String Compression
Given a string, generate all possible strings by changing each letter to lowercase or uppercase. Return a list of all these possible strings.
#16. Letter Case Permutation
Find two numbers in a given array that add up to a specific target value, and return their indices. Essentially, you need to efficiently locate the pair that satisfies the sum requirement.
#17. Two Sum
Imagine you are looking at a city skyline. Given the locations and heights of buildings, find the outline of the skyline formed by these buildings when viewed from a distance.
#18. The Skyline Problem
Given a list of words, group together all the anagrams. Anagrams are words that contain the same letters rearranged.
#19. Group Anagrams
Determine if any word in a given sentence starts with a specified search word. Return true if the search word is a prefix of at least one word in the sentence, and false otherwise.
#20. Check If a Word Occurs As a Prefix of Any Word in a Sentence