Showing 89 questions
Imagine a tree where some nodes have coins. You want to collect all the coins, but you can only traverse the tree. Find the minimum number of edges you need to travel to collect all the coins.
#1. Collect Coins in a Tree
Imagine a tree where some nodes have apples. Find the minimum time needed to collect all the apples and return to the root, considering the time to travel each edge.
#2. Minimum Time to Collect All Apples in a Tree
You are given a square matrix representing an image. Rotate the image by 90 degrees clockwise in-place.
#3. Rotate Image
Find the longest palindromic substring within a given string. A palindromic substring reads the same forwards and backward.
#4. Longest Palindromic Substring
You are a robber planning to rob houses along a street. Maximize your loot, but be careful - adjacent houses have connected security systems that will trigger an alarm if you rob them both.
#5. House Robber
Find the "lucky numbers" in a matrix. A lucky number is the smallest element in its row and the largest in its column.
#6. Lucky Numbers in a Matrix
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.
#7. Spiral Matrix
Write a program that prints numbers from 1 to n, replacing multiples of 3 with "Fizz", multiples of 5 with "Buzz", and multiples of both with "FizzBuzz".
#8. Fizz Buzz
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.
#9. LRU Cache
You are given a list of stock prices over time. Determine the maximum profit you can make with at most three transactions.
#10. Find Third Transaction
Determine how many words in a given sentence are valid according to a specific set of rules. You'll need to check each word individually against the validity criteria.
#11. Number of Valid Words in a Sentence
Find the sum of the first n numbers that are palindromic in both base 10 and base k (where k is a given integer). You need to generate and check numbers until you find n k-mirror numbers.
#12. Sum of k-Mirror Numbers
Find the maximum difference between two numbers in an array, where the larger number appears after the smaller number. If no such pair exists, return -1.
#13. Maximum Difference Between Increasing Elements
You are given the coordinates of two rectangles. Determine the largest possible square that can fit entirely within both rectangles.
#14. Find the Largest Area of Square Inside Two Rectangles
Simulate a game of Snakes and Ladders on a board represented by an array. Find the minimum number of dice rolls to reach the final square, considering snake and ladder shortcuts.
#15. Snakes and Ladders
Determine if a binary string contains at most one contiguous block of '1's. The '1's must form a single, uninterrupted sequence.
#16. Check if Binary String Has at Most One Segment of Ones
Find the contiguous subarray within a given array of numbers which has the largest sum. Return the sum of this subarray.
#17. Maximum Subarray
Find the number of substrings in a string where each character appears the same number of times. The common count must be a specific given value.
#18. Number of Equal Count Substrings
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.
#19. Word Search II
You are given an array and need to make all elements equal. Find the minimum cost to achieve this, where the cost depends on how much each element is changed.
#20. Minimum Cost to Make Array Equal