Given 2 lists, find the common items in both lists. 这道题要求找出两个列表中的公共元素,最直接的做法是先遍历其中一个列表并用哈希集合记录出现过的值,再扫描第二个列表,判断哪些元素也出现在集合中。这样可以把查找从线性时间降到接近 O(1),整体复杂度通常…
Problem Statement Given two strings A and B , return the 0-based starting index of the first contiguous substring in A that is a permutation (anagram) o…
You are building an in-memory, single-threaded analytics service for ChatGPT chat sessions. It ingests a real-time, globally non-decreasing stream of in…
Given a web page, we want to annotate text segments that may overlap. (One example is Google Docs, where you can highlight some text and add a comment.)…
Assume that Airbnb decided to enable search on user reviews. In order to make the search better, you need to tag specific words in the review. The searc…
Given an integer array nums of length n and an integer target , find three integers in nums such that the sum is closest to target . Return the sum of t…
Build a simple class that implements a basic in-memory service that: Records a song play event for a given song id Returns play counts for individual so…
An infected plant spreads infection to neighboring plants. If a plant is surrounded by D infected plants, it also becomes infected. How many days until…
You are given a matrix whose elements are initially set to 0 and a starting position (startRow, startCol) (0-based indexing). Fill the matrix with incre…
Build a reservation system for a predefined set of conference rooms given as a list of room IDs [roomA, roomB, …] . It should have a method like sched…
You have a dataset which contains examples labeled with different classes (single-label, multiple classes); for example, an animal image classification…
Social Network Implement follow , unfollow , snapshot , and is_following . The snapshot captures the current state of all relationships and returns an i…
We are designing a system for officers to check out a body worn camera from a pool of available cameras. We need an object to store a collection of came…
Implement a function that merges multiple sorted integer streams into a single sorted list. interface SortedIntegerStream { int next(); // get the integ…
A new restaurant in my hometown gets most of its income from a few important clients. I want to model the probability that a client comes to my restaura…
You are given an array Parkings of size N , which represents parking spaces, and an integer K , which represents the number of cars you need to park in…
Imagine that each state is assigned a number of votes as follows: Alabama = 9 Alaska = 3 Arizona = 11 Arkansas = 6 … Wyoming = 3 For the purpose of th…