Showing 26 questions
You're given quantities of different products and a number of stores. Distribute the products among the stores, maximizing the number of products each store receives, but minimizing the largest amount any single store gets.
#1. Minimized Maximum of Products Distributed to Any Store
Given an array of integers and a list of queries, count the number of peaks within various subarrays specified by the queries.
#2. Peaks in Array
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 are given a collection of intervals. Merge all overlapping intervals into a single interval and return the result.
#4. Merge Intervals
You're given two sorted lists. Combine them into a single sorted list containing all elements from both original lists.
#5. Merge Two Sorted Lists
Determine if a string containing parentheses is valid. A valid string has matching and properly nested opening and closing parentheses.
#6. Valid Parentheses
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.
#7. Letter Combinations of a Phone Number
Calculate the angle between the hour and minute hands on a clock, given a specific hour and minute. Be mindful of the direction and choose the smaller angle.
#8. Angle Between Hands of a Clock
Imagine you are looking at a city skyline. Given the locations and heights of buildings, find the outline of the skyline formed by these buildings when viewed from a distance.
#9. The Skyline Problem
Design and implement a Least Frequently Used (LFU) cache. The cache should efficiently store key-value pairs, evicting the least frequently used items when it reaches capacity.
#10. LFU Cache
You are given the head of a singly linked list. Reverse the list and return the new head.
#11. Reverse Linked List
Given a list of words, group together all the anagrams. Anagrams are words that contain the same letters rearranged.
#12. Group Anagrams
You're given a string of parentheses. Find the minimum number of parentheses you need to add to make the string valid (i.e., properly balanced).
#13. Minimum Add to Make Parentheses Valid
Given a sorted array, remove the duplicate elements in-place such that each unique element appears only once. Return the new length of the array.
#14. Remove Duplicates from Sorted Array
Find the longest palindromic substring within a given string. A palindromic substring reads the same forwards and backward.
#15. Longest Palindromic Substring
Given a linked list, rotate the list to the right by a given number of places. The rotation should be done in place without creating a new list.
#16. Rotate List
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.
#17. LRU Cache
You're given an array where every number appears twice, except for two numbers that appear only once. Find those two unique numbers.
#18. Single Number III
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
Determine if any value appears at least twice in an array of numbers. Return true if duplicates exist; otherwise, return false.
#20. Contains Duplicate