Showing 22 questions
You're given an array representing weights. Implement a function to randomly pick an index from the array, where the probability of picking each index is proportional to its weight.
#1. Random Pick with Weight
Imagine a map where cities are connected by roads. Given a list of roads, find how many separate groups of connected cities (provinces) there are.
#2. Number of Provinces
Find the minimum number of operations to reduce a given positive integer to 0. You can either subtract a power of 2 or add a power of 2 in each operation.
#3. Minimum Operations to Reduce an Integer to 0
Find the largest possible sum of a contiguous subarray after deleting at most one element from the original array. You need to consider the cases with no deletion and with one deletion.
#4. Maximum Subarray Sum with One Deletion
Determine if a given integer is a power of four. That is, can the number be expressed as 4 raised to some integer power?
#5. Power of Four
Simulate multiplication of two non-negative integers represented as strings. Return the product, also represented as a string.
#6. Multiply Strings
Find the maximum possible sum of a non-empty subarray within a circular array. The circular array means the end connects to the beginning.
#7. Maximum Sum Circular Subarray
Determine if a string matches a pattern containing wildcard characters '?' (matches any single character) and '*' (matches any sequence of characters, including the empty sequence).
#8. Wildcard Matching
Find the common elements present in two given arrays. Return an array containing these intersecting elements, ensuring each element appears only once.
#9. Intersection of Two Arrays
Simulate the Game of Life, updating the state of a board based on the rules of cell survival and death in each generation. Modify the board in place to represent the next generation.
#10. Game of Life
You are given a list of words. Find the longest possible chain of words where each word is formed by adding exactly one letter to its predecessor.
#11. Longest String Chain
You are given a board of characters and a list of words. Find all the words from the list that can be formed by traversing adjacent cells on the board.
#12. Word Search II
You are given k sorted lists. Combine all of their elements into a single sorted list and return it.
#13. Merge k Sorted Lists
Simulate a basic memory allocator. You'll need to allocate blocks of memory, track their IDs, and free them based on their ID.
#14. Design Memory Allocator
You're given courses with prerequisites and time to complete each. Find the minimum time to finish all courses, taking dependencies and parallel study into account.
#15. Parallel Courses III
You're given boxes of products and suppliers offering packages of various sizes. Find the minimum wasted space when fitting all the products into one supplier's package.
#16. Minimum Space Wasted From Packaging
Implement a hash map data structure from scratch. You need to handle basic operations like insertion, retrieval, and deletion of key-value pairs.
#17. Design HashMap
Implement a Tic-Tac-Toe game where players take turns placing their marks. Design the game logic to efficiently determine the winner after each move.
#18. Design Tic-Tac-Toe
You are given a list of meeting time intervals. Determine the minimum number of conference rooms required to accommodate all the meetings without any overlap.
#19. Meeting Rooms II
Implement a search suggestion system. Given a search word and a list of product names, return the top 3 product suggestions after each character of the search word is typed.
#20. Search Suggestions System