Showing 88 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
Given an array of integers, find the number of subarrays that contain exactly K distinct integers. A subarray is a contiguous part of the array.
#2. Subarrays with K Different Integers
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.
#3. Trapping Rain Water
Find the number of contiguous subarrays within a given array whose product is strictly less than a target value k. The goal is to efficiently count these subarrays by considering the product of their elements.
#4. Subarray Product Less Than K
Determine if a string containing parentheses is valid. A valid string has matching and properly nested opening and closing parentheses.
#5. Valid Parentheses
Given a list of words, group together all the anagrams. Anagrams are words that contain the same letters rearranged.
#6. Group Anagrams
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.
#7. LRU Cache
Find the number of distinct sequences you can generate by rolling a die 'n' times, subject to certain constraints on consecutive rolls. Specifically, you cannot roll the same number twice in a row, and specific pairs of rolls are forbidden.
#8. Number of Distinct Roll Sequences
Given a number 'n', generate all possible well-formed (balanced) parentheses strings of length 2*n. For instance, if n=3, you need to create all valid combinations like '((()))', '(()())', etc.
#9. Generate Parentheses
You're given a string and allowed to swap adjacent characters under certain constraints. Find the lexicographically smallest string you can achieve after performing these swaps.
#10. Lexicographically Smallest String After Operations With Constraint
You're given two separate tree structures. Find the smallest possible diameter of the tree formed after merging the two trees at any possible nodes.
#11. Find Minimum Diameter After Merging Two Trees
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.
#12. Container With Most Water
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
You are given a collection of intervals. Merge all overlapping intervals into a single interval and return the result.
#14. Merge Intervals
Given an array, rearrange it so that all zeros are moved to the end while maintaining the relative order of the non-zero elements.
#15. Move Zeroes
Implement a basic hash map data structure. You'll need to handle storing key-value pairs, retrieving values by key, and removing entries.
#16. Design HashMap
Convert a given string into a zigzag pattern with a specified number of rows. Then read the characters row by row to return the converted string.
#17. Zigzag Conversion
Find the smallest positive integer that is missing from a given array of integers. You need to do this in linear time and constant extra space.
#18. First Missing Positive
Given a grid representing land and water, count the number of distinct islands. An island is formed by connected land cells.
#19. Number of Islands
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