Showing 496 questions
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.
#1. Bus Routes
Imagine an empty grid that represents the sea. You are given a sequence of coordinates to add land (islands) to the grid one by one. Determine the number of islands after each addition.
#2. Number of Islands II
You are given a sorted list of words from an alien language and need to deduce the order of the letters in that language. Determine the alien alphabet order based on the given word sequence.
#3. Alien Dictionary
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.
#4. Construct Quad Tree
You're a taxi driver trying to maximize your earnings. Given a list of rides with start, end, and tip, find the maximum profit you can make by picking rides that don't overlap.
#5. Maximum Earnings From Taxi
Find the longest continuous subarray where the absolute difference between any two elements is less than or equal to a given limit. Return the length of this subarray.
#6. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit
You're given an array of integers and a number K. You can negate any number in the array up to K times. Maximize the sum of the array after performing at most K negations.
#7. Maximize Sum Of Array After K Negations
Given a grid representing land and water, count the number of distinct islands. An island is formed by connected land cells.
#8. Number of Islands
You are given equations represented by pairs of variables and their corresponding values. Your task is to evaluate queries based on these equations, determining the value of expressions if possible, or returning -1.0 if not.
#9. Evaluate Division
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.
#10. Two Sum
Given a number, find the closest palindrome to it. You need to return the palindrome that is nearest to the given number, considering both larger and smaller palindromes.
#11. Find the Closest Palindrome
Find the kth smallest value in a given Binary Search Tree. Return the node's value that holds this smallest element.
#12. Kth Smallest Element in a BST
You are given a board of characters and a list of words. Find all the words from the list that can be formed by traversing adjacent cells on the board.
#13. Word Search II
You're given daily stock prices. Find the maximum profit you can make by buying and selling the stock once. You must buy before you sell.
#14. Best Time to Buy and Sell Stock
Calculate a new array where each element is the product of all numbers in the original array, excluding the number at that index. Do this efficiently without using division.
#15. Product of Array Except Self
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.
#16. Word Search
You're given a sorted array of integers. Return a new array containing the squares of each number, also sorted in non-decreasing order.
#17. Squares of a Sorted Array
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.
#18. LRU Cache
Given a sequence of words and a line width, format the text to fit within the specified width. You must justify the text, distributing extra spaces evenly between words.
#19. Text Justification
Design a calendar system. You need to implement a function to book new events, but avoid double booking (overlapping events).
#20. My Calendar I