Showing 167 questions
Find the length of the longest substring within a given string that contains no repeating characters. The substring must be contiguous.
#1. Longest Substring Without Repeating Characters
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.
#2. LRU Cache
Determine if a string containing parentheses is valid. A valid string has matching and properly nested opening and closing parentheses.
#3. Valid Parentheses
Design a stack that supports push, pop, top, peekMax, and popMax operations, all in O(1) time complexity where possible. The challenge lies in efficiently tracking and retrieving the maximum value within the stack.
#4. Max Stack
Given an array representing the height of bars, calculate how much water can be trapped between them after rain. Think about finding the maximum height to the left and right of each bar.
#5. Trapping Rain Water
You are given a collection of intervals. Merge all overlapping intervals into a single interval and return the result.
#6. Merge Intervals
You're given a set of intervals. The goal is to divide these intervals into the fewest possible groups, where no intervals within a group overlap.
#7. Divide Intervals Into Minimum Number of Groups
Determine if a given string can be segmented into a space-separated sequence of words from a dictionary. You are given a string and a dictionary of words; can you break the string down using words from the dictionary?
#8. Word Break
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.
#9. Best Time to Buy and Sell Stock
Find the number of elements in an array that appear with the highest frequency. Essentially, count how many times the most frequent number occurs.
#10. Count Elements With Maximum Frequency
You're given workers with varying strengths and tasks of different difficulties. Find the maximum number of tasks you can assign to workers, where a worker's strength must be greater than or equal to the task's difficulty.
#11. Maximum Number of Tasks You Can Assign
Given a string of digits, find the number of ways to split it into valid numbers, where each number must be positive and non-decreasing.
#12. Number of Ways to Separate Numbers
Find the middle node of a given linked list. If the list has an even number of nodes, return the second middle node.
#13. Middle of the Linked List
Imagine a value changing over time based on given rules. Your task is to determine the value of this evolving number after a specific duration.
#14. Find the N-th Value After K Seconds
Generate a circular sequence of binary numbers of a given length, ensuring consecutive numbers differ by only one bit. You need to find a permutation that satisfies this Gray code property.
#15. Circular Permutation in Binary Representation
Given an array, count how many triplets of numbers satisfy specific absolute difference conditions between their values. The goal is to find 'good' triplets based on these constraints.
#16. Count Good Triplets in an Array
You're given two arrays and can perform certain operations on them to make them similar. Find the minimum number of operations needed to make the arrays have the same set of elements, considering only the parity (odd/even) of the numbers.
#17. Minimum Number of Operations to Make Arrays Similar
You're given a sorted array that has been rotated, and a target value. Find the index of the target value in the rotated array, or return -1 if it's not present.
#18. Search in Rotated Sorted Array
You're given an integer n and a start number. Generate an array based on n and start, then calculate the bitwise XOR of all elements in the array.
#19. XOR Operation in an Array
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.
#20. Two Sum