Showing 37 questions
Traverse a given matrix in a spiral pattern, returning all elements in the order you visit them. Essentially, walk around the matrix layer by layer, adding elements to a list.
#1. Spiral Matrix
Given a grid representing land and water, count the number of distinct islands. An island is formed by connected land cells.
#2. Number of Islands
Imagine you're standing at a fixed location looking at points on a 2D plane. Determine the maximum number of points you can see within a given field of view by rotating your position.
#3. Maximum Number of Visible Points
You are given a collection of video clips and a target duration. Determine the minimum number of clips needed to cover the entire duration from start to finish by stitching them together.
#4. Video Stitching
Find the minimum distance between two given words in a list of words. You are given a list of words and two target words; determine the shortest distance between them in the list.
#5. Shortest Word Distance
Given a list of words, group together all the anagrams. Anagrams are words that contain the same letters rearranged.
#6. Group Anagrams
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.
#7. Search Suggestions System
Determine if it is possible to finish all courses given prerequisites. Some courses must be taken before others; can you find a valid order?
#8. Course Schedule
Design a data structure that efficiently finds the median of a constantly updating stream of numbers. You need to support adding new numbers and querying the current median.
#9. Find Median from Data Stream
Given a list of daily temperatures, find how many days you have to wait until a warmer temperature. Return a list where each element represents the waiting days for each day's temperature.
#10. Daily Temperatures
You're given a list of courses and their prerequisites. Determine a valid order in which you can take all the courses, respecting the dependencies. If it's impossible to finish all courses, indicate that.
#11. Course Schedule II
You are given the positions of houses and heaters on a line. Find the minimum radius of heaters required to cover all houses.
#12. Heaters
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.
#13. Making A Large Island
You're given a list of words and need to efficiently find the shortest distance between two specified words within that list. Unlike a simpler version, you'll be asked to do this repeatedly for different word pairs on the *same* word list.
#14. Shortest Word Distance II
You are given a collection of intervals. Merge all overlapping intervals into a single interval and return the result.
#15. Merge Intervals
Transform a binary tree into a linked list, where the linked list represents the tree's pre-order traversal. The 'right' pointer should act as the 'next' pointer in the linked list, and the 'left' pointer should always be null.
#16. Flatten Binary Tree to Linked List
Implement a basic calculator to evaluate a simple expression string. The expression can contain non-negative integers, '+', '-', '*', '/' operators, and spaces; integer division should truncate toward zero.
#17. Basic Calculator II
Determine if two binary trees are flip-equivalent. Flip-equivalent trees can be made identical by some number of flips of left and right children at any node.
#18. Flip Equivalent Binary Trees
You are given k sorted lists. Combine all of their elements into a single sorted list and return it.
#19. Merge k Sorted Lists
You are given a grid of oranges, some fresh, some rotten. Rotten oranges contaminate adjacent fresh oranges; find the minimum time until all oranges are rotten.
#20. Rotting Oranges