Showing 67 questions
Find the lowest common ancestor of two nodes in a given binary tree. The lowest common ancestor is defined as the farthest node from the root that is an ancestor of both nodes.
#1. Lowest Common Ancestor of a Binary Tree
The problem asks you to find the total number of distinct palindromic subsequences within a given string. Remember that subsequences don't have to be contiguous.
#2. Count Palindromic Subsequences
You're given a list of votes for teams, where each vote ranks the teams in order. Determine the final ranking of the teams based on these votes, prioritizing teams with higher rankings in the votes.
#3. Rank Teams by Votes
Design a Snake game where the snake moves on a grid, eats food to grow, and the game ends if it hits the wall or itself. Implement the movement logic and growth mechanics of the snake.
#4. Design Snake Game
You're given a list of employee access times. Identify and return the employees who have accessed the system at least three times within a one-hour period.
#5. High-Access Employees
Design a logger that prevents duplicate messages from being printed within a certain time window. Determine if a message should be printed based on its timestamp and content, considering rate limiting.
#6. Logger Rate Limiter
You are given a collection of intervals. Merge all overlapping intervals into a single interval and return the result.
#7. Merge Intervals
You are given a list of meeting time intervals. Determine the minimum number of conference rooms required to accommodate all the meetings without any overlap.
#8. Meeting Rooms II
Imagine a company with several branches. You need to find the number of different combinations of branches you can close down, given some restrictions on which branches depend on others.
#9. Number of Possible Sets of Closing Branches
Find the minimum time required to visit all cells in a grid, starting from the top-left cell. You can only move to adjacent cells, but some cells have time restrictions that must be met before you can enter.
#10. Minimum Time to Visit a Cell In a Grid
Find the maximum sum of a subarray that satisfies a given 'goodness' condition based on the frequency of its elements. The 'goodness' is determined by whether the count of each number in the subarray is at least k.
#11. Maximum Good Subarray Sum
Given a grid of numbers, determine the maximum width of each column. Return an array containing the widths of each column.
#12. Find the Width of Columns of a Grid
Determine if an equation where words represent numbers can be solved such that each letter maps to a unique digit. You need to check if a valid assignment of digits to letters exists to make the equation true.
#13. Verbal Arithmetic Puzzle
You're given an array and allowed to swap elements based on a condition. The goal is to make the array lexicographically smallest by performing these swaps.
#14. Make Lexicographically Smallest Array by Swapping Elements
Imagine a rectangular field surrounded by fences. You're given the positions of the fences and need to remove some to form the largest possible square field. Find the maximum area of that square.
#15. Maximum Square Area by Removing Fences From a Field
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.
#16. Text Justification
You're given a list of rectangles. Find the rectangle with the longest diagonal, and return its area. If there's a tie for longest diagonal, return the maximum area among those rectangles.
#17. Maximum Area of Longest Diagonal Rectangle
You're given two strings and cost to convert between letters. Find the minimum total cost to make the first string equal to the second by changing letters.
#18. Minimum Cost to Convert String I
You're given an array of numbers and can modify them by adding or subtracting a fixed value. Find the smallest non-negative integer that's missing from the array after these modifications.
#19. Smallest Missing Non-negative Integer After Operations
You're given two strings and a set of possible substring replacements with associated costs. Find the minimum cost to transform the first string into the second by applying these replacements.
#20. Minimum Cost to Convert String II