Showing 49 questions
The count-and-say sequence is generated iteratively. Given a starting number, compute the next number in the sequence by describing the previous one.
#1. Count and Say
You're given a list of flight tickets, each representing a departure and arrival airport. Reconstruct the itinerary by visiting all the airports in the lexicographically smallest order, starting from "JFK".
#2. Reconstruct Itinerary
You are given a list of transactions between people. Determine the minimum number of transactions needed to settle all debts, such that everyone owes or is owed exactly zero.
#3. Optimal Account Balancing
Find the shortest path from the top-left to the bottom-right corner of a grid. You can eliminate a limited number of obstacles along the way.
#4. Shortest Path in a Grid with Obstacles Elimination
Find the number of subarrays in a given array whose "score" (defined as the product of the subarray's length and sum) is less than a target value k. Efficiently count these subarrays, avoiding brute force.
#5. Count Subarrays With Score Less Than K
You're given a list of jobs with start times, end times, and profits. Find the maximum profit you can obtain by scheduling a subset of jobs that don't overlap.
#6. Maximum Profit in Job Scheduling
Imagine you're planning a trip using a network of bus routes. Given a set of routes and start/end locations, find the fewest number of buses you must take to reach your destination.
#7. Bus Routes
Given a string of digits, find all valid ways to insert '+', '-', or '*' operators to achieve a target number. You need to explore all possible combinations of operators and numbers formed from the input string.
#8. Expression Add Operators
Determine the fewest number of subsequences from a source string needed to construct a target string. Each subsequence must match a portion of the source string.
#9. Shortest Way to Form String
Rearrange the characters in a given string such that no two adjacent characters are the same. If such an arrangement is possible, return it; otherwise, return an empty string.
#10. Reorganize String
Determine if one string is a subsequence of another. That is, check if you can form the first string by deleting characters from the second string without changing the order of the remaining characters.
#11. Is Subsequence
Design a search autocomplete system that suggests relevant sentences based on user input. The system should efficiently return the top k most relevant sentences ranked by frequency.
#12. Design Search Autocomplete System
Find the longest word in a given dictionary that can be built one character at a time using other words in the dictionary. If there are multiple such words, return the lexicographically smallest one.
#13. Longest Word in Dictionary
You're given a list of numbers and how many times each number appears. Your task is to find the median value from this frequency distribution.
#14. Find Median Given Frequency of Numbers
Multiply two sparse matrices represented as arrays of arrays. Optimize your solution to avoid unnecessary calculations on zero elements.
#15. Sparse Matrix Multiplication
Given a set of coin denominations and a target amount, find the minimum number of coins needed to reach that amount. You can assume you have an unlimited supply of each coin type.
#16. Coin Change
You're given a list of meeting times and need to figure out which room hosted the most meetings. Simulate the meeting schedules to track room usage and identify the busiest room.
#17. Meeting Rooms III
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.
#18. String Compression
Given an array of numbers, can you find how many ways you can add a plus or minus sign before each number so that the sum of the entire array equals a specific target number?
#19. Target Sum
Find the number of unique paths from the top-left to the bottom-right corner of a grid, but with obstacles blocking some paths. You need to navigate the grid avoiding the obstacles.
#20. Unique Paths II