Showing 46 questions
Determine if it is possible to finish all courses given prerequisites. Some courses must be taken before others; can you find a valid order?
#1. Course Schedule
Find the length of the longest substring within a given string that contains no repeating characters. The substring must be contiguous.
#2. Longest Substring Without Repeating Characters
Determine the fewest modifications needed to transform a binary string into an alternating pattern (e.g., "0101" or "1010"). You can change '0' to '1' or '1' to '0'.
#3. Minimum Changes To Make Alternating Binary String
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.
#4. Basic Calculator II
Given a grid representing land and water, count the number of distinct islands. An island is formed by connected land cells.
#5. Number of Islands
You are given a collection of intervals. Merge all overlapping intervals into a single interval and return the result.
#6. Merge Intervals
Implement a circular queue data structure with a fixed size. You'll need to handle enqueueing, dequeueing, and checking if the queue is full or empty efficiently.
#7. Design Circular Queue
Find the k most frequent elements in a given array of numbers. Return the top k elements based on their frequency.
#8. Top K Frequent Elements
You are given components of water molecules: hydrogen and oxygen. Your task is to assemble complete H2O molecules using the available components, ensuring thread safety.
#9. Building H2O
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.
#10. LRU Cache
Given a string of digits, return all possible letter combinations that the number could represent, using the typical phone keypad mapping. The goal is to generate all valid combinations in any order.
#11. Letter Combinations of a Phone Number
Determine if a string containing parentheses is valid. A valid string has matching and properly nested opening and closing parentheses.
#12. Valid Parentheses
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.
#13. Best Time to Buy and Sell Stock
Find all unique triplets in an array that sum to zero. You'll need to consider the potential for duplicate numbers and avoid duplicate triplets in your solution.
#14. 3Sum
Determine the total number of continuous subarrays within a given array that sum up to a specific target value, k.
#15. Subarray Sum Equals K
Given an array, rearrange it so that all zeros are moved to the end while maintaining the relative order of the non-zero elements.
#16. Move Zeroes
You are given an array representing the heights of vertical lines. Find two lines that, together with the x-axis, form a container that holds the most water.
#17. Container With Most Water
Imagine a grid of land and water. Find the largest connected area of land and return its size.
#18. Max Area of Island
Determine if two strings are anagrams of each other, meaning they contain the same characters in a different order. You need to check if one string can be rearranged to form the other.
#19. Valid Anagram
Rearrange the characters in a given string such that no two adjacent characters are the same. If such an arrangement is possible, return it; otherwise, return an empty string.
#20. Reorganize String