Showing 85 questions
Simulate a single-threaded CPU processing tasks with varying arrival times and processing durations. Determine the order in which the CPU processes the tasks to minimize idle time, and return the processing order.
#1. Single-Threaded CPU
Imagine a grid representing rooms, some empty, some with walls, and some with gates. Fill each empty room with the distance to its nearest gate.
#2. Walls and Gates
Find the longest path in a matrix where each step increases in value. You can only move up, down, left, or right.
#3. Longest Increasing Path in a Matrix
Convert a Roman numeral string into its corresponding integer value. The input string will represent a valid Roman numeral.
#4. Roman to Integer
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.
#5. Search Suggestions System
You're given job difficulties and profits, and worker abilities. Find the maximum total profit you can achieve by assigning workers to jobs they are capable of doing.
#6. Most Profit Assigning Work
Given a sorted array, find the k closest elements to a given value. Return the k closest elements in sorted order.
#7. Find K Closest Elements
Find the maximum sum of any path in a binary tree, where a path can start and end at any node. The path must contain at least one node.
#8. Binary Tree Maximum Path Sum
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.
#9. Maximum Profit in Job Scheduling
Koko wants to eat all the bananas in some piles within a certain time. Find the minimum eating speed that allows her to finish on time.
#10. Koko Eating Bananas
Design a file system that allows you to create paths and associate values with them. Implement operations to create new paths and retrieve the value associated with a path.
#11. Design File System
Determine if two strings can be made identical by performing at most one swap of characters in one of the strings. That is, can you swap two letters in string 'a' so that it becomes equal to string 'b'?
#12. Check if One String Swap Can Make Strings Equal
You are given a grid where some cells are buildings and others are obstacles or empty land. Find the shortest distance a person can travel from an empty land cell to reach all the buildings.
#13. Shortest Distance from All Buildings
Determine the fewest character replacements needed to transform one string into an anagram of another. Essentially, find the minimum steps to make two strings have the same character frequencies.
#14. Minimum Number of Steps to Make Two Strings Anagram
Given a positive integer, find the smallest integer greater than the input that can be formed by rearranging its digits. If no such integer exists, return -1.
#15. Next Greater Element III
Determine if two strings can become identical after swapping exactly two characters in one of them. Consider if they can be 'buddy strings'.
#16. Buddy Strings
You're given a grid representing land and water. Change one water cell to land to maximize the size of the largest connected land area (island) and return that maximum size.
#17. Making A Large Island
Implement an in-memory file system with basic operations like creating directories, adding files, and listing contents. The file system should support path-based navigation.
#18. Design In-Memory File System
Evaluate a string expression that includes basic arithmetic operations (+, -, *, /) and parentheses. Handle operator precedence and calculate the final result.
#19. Basic Calculator III
You are given two binary matrices representing islands. Determine the number of 'sub-islands' in the second grid, where a sub-island is an island entirely contained within an island of the first grid.
#20. Count Sub Islands