Showing 26 questions
Design a data structure to check if the last 'k' integers in a stream are equal to a given number. Implement a function that efficiently determines if the last 'k' elements are consecutive and match the given value.
#1. Find Consecutive Integers from a Data Stream
Determine the maximum level of nested parentheses within a given string. Essentially, find the deepest level of parentheses in the expression.
#2. Maximum Nesting Depth of the Parentheses
Given a grid representing land and water, count the number of distinct islands. An island is formed by connected land cells.
#3. Number of Islands
You're given a linked list where each node has a regular 'next' pointer and a 'random' pointer. Create a deep copy of this list, preserving both the next and random pointer relationships.
#4. Copy List with Random Pointer
Determine if a string containing parentheses is valid. A valid string has matching and properly nested opening and closing parentheses.
#5. Valid Parentheses
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.
#6. Trapping Rain Water
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.
#7. Two Sum
Determine the number of prime numbers less than a given non-negative integer, n. You need to efficiently count how many primes exist within that range.
#8. Count Primes
Find the length of the longest substring within a given string that contains no repeating characters. The substring must be contiguous.
#9. 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.
#10. LRU Cache
Determine whether an integer is a palindrome. That is, it reads the same forwards and backward.
#11. Palindrome Number
Maximize your profit by buying and selling a stock multiple times. You're given an array representing stock prices, and can make as many transactions as you want.
#12. Best Time to Buy and Sell Stock II
You are given two sorted integer arrays. Merge the second array into the first one, maintaining the sorted order.
#13. Merge Sorted Array
You are given a square matrix representing an image. Rotate the image by 90 degrees clockwise in-place.
#14. Rotate Image
You're given two sorted lists. Combine them into a single sorted list containing all elements from both original lists.
#15. Merge Two Sorted Lists
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.
#16. Container With Most Water
Reverse the digits of a given 32-bit signed integer. Handle potential overflow by returning 0 if the reversed value is outside the valid range.
#17. Reverse Integer
You are climbing a staircase with n steps. Find how many distinct ways you can climb to the top, given that you can climb one or two steps at a time.
#18. Climbing Stairs
Reverse the order of words in a given string. The input string may contain leading or trailing spaces, which should be removed in the output.
#19. Reverse Words in a String
Calculate a new array where each element is the product of all numbers in the original array, excluding the number at that index. Do this efficiently without using division.
#20. Product of Array Except Self