DoorDash计算机科学面试真题

职位分类
全部
数据相关
计算机科学
人工智能
产品经理
BQ
面试题
全部(52)
OOD(0)
Algorithm(48)
System Design(4)
高频题(1)
Math(0)
全部(52)
OOD(0)
Algorithm(48)
System Design(4)
高频题(1)
Math(0)
1."Buddy Strings Problem"
2.两个数组的重合区域
3.Food Rating System Design and Implementation
4.Longest Valid Parentheses Substring Length
5.In-Memory File System Design
6."Minimum Steps to Make Two Strings Anagrams"
7.Dominoes Falling Simulation
8."Maximizing Profit by Assigning Jobs to Workers Based on Difficulty and Ability"
9."Check if Two Letters Can Be Swapped to Make Strings Equal"
10.Minimum Swaps to Make Strings K-Similar
11.Largest Rectangle in Histogram
12.Finding Lowest Common Ancestor in a Binary Search Tree
13.Binary Tree Vertical Order Traversal
14.Binary Tree Right Side View
15.Binary Tree Level Order Traversal II
16.Binary Tree Level Order Traversal
17.Remove Duplicates from Sorted List
18.Remove Duplicates from Sorted List II
19.Swap Nodes in Pairs in Linked List
20.Merge K Sorted Linked Lists
21.Possible Bipartition
22.Similar restaurants
23.Delivery Schedule
24.API delimiter
25.Similar restaurants
26.Update menu
27.Number of drop in a gateway
28.Balls left after collision
29.Max profit for cooking
30.Circuit breaker design
31.Opening and closing time for a restaurant
32.Maximizing Profit from Non-Overlapping Part-Time Jobs
33.SwimInRisingWater
34.Minimum Eating Speed to Finish Bananas
35.Minimum Size Subarray Sum
36.Remove smallest peaks in order
37.Min number of operations to update menu
38.Return all timestamp
39.Min time from top left to bottom right
40.Maximum Path Sum in Binary Tree with Leaf-to-Leaf Requirement
41.find the length of the longest path that has the same values
42.消消乐
43.Asteroid Collision
44.Number of requests dropped
45.Design an API to Display Orders for Dashers Based on Rank and Pickup Time
46.Find the Shortest Distance to Cities with Matching Coordinates
47.Island Perimeter Variant
48.System Design for a Messaging Application
49.Comparing Two Trees
50.Design a Food Review System
51.Optimize Time Complexity
52.Find the Closest Dashmart to the Maximum Number of Customers
1. "Buddy Strings Problem"
Given two strings s and goal, return true if you can swap two letters in s so the result is equal to goal, otherwise, return false.

Swapping letters is defined as taking two indices i and j (0-indexed) such that i != j and swapping the characters at s[i] and s[j].

  • For example, swapping at indices 0 and 2 in "abcd" results in "cbad".
 

Example 1:

Input: s = "ab", goal = "ba"
Output: true
Explanation: You can swap s[0] = 'a' and s[1] = 'b' to get "ba", which is equal to goal.

Example 2:

Input: s = "ab", goal = "ab"
Output: false
Explanation: The only letters you can swap are s[0] = 'a' and s[1] = 'b', which results in "ba" != goal.

Example 3:

Input: s = "aa", goal = "aa"
Output: true
Explanation: You can swap s[0] = 'a' and s[1] = 'a' to get "aa", which is equal to goal.

 

Constraints:

  • 1 <= s.length, goal.length <= 2 * 104
  • s and goal consist of lowercase letters.
2. 两个数组的重合区域
两人大小一样的二维数组,都是0或1,返回数组a是1的连续区域数量,而且相同的区域在b也是1。例如a={{1,1,0,1,0,1}},b={{1,1,1,0,0,1}},返回2。follow up是O(1)space。
3. Food Rating System Design and Implementation
Design a food rating system that can do the following:

  • Modify the rating of a food item listed in the system.
  • Return the highest-rated food item for a type of cuisine in the system.
Implement the FoodRatings class:

  • FoodRatings(String[] foods, String[] cuisines, int[] ratings) Initializes the system. The food items are described by foods, cuisines and ratings, all of which have a length of n.
    • foods[i] is the name of the ith food,
    • cuisines[i] is the type of cuisine of the ith food, and
    • ratings[i] is the initial rating of the ith food.
  • void changeRating(String food, int newRating) Changes the rating of the food item with the name food.
  • String highestRated(String cuisine) Returns the name of the food item that has the highest rating for the given type of cuisine. If there is a tie, return the item with the lexicographically smaller name.
Note that a string x is lexicographically smaller than string y if x comes before y in dictionary order, that is, either x is a prefix of y, or if i is the first position such that x[i] != y[i], then x[i] comes before y[i] in alphabetic order.

 

Example 1:

Input
["FoodRatings", "highestRated", "highestRated", "changeRating", "highestRated", "changeRating", "highestRated"]
[[["kimchi", "miso", "sushi", "moussaka", "ramen", "bulgogi"], ["korean", "japanese", "japanese", "greek", "japanese", "korean"], [9, 12, 8, 15, 14, 7]], ["korean"], ["japanese"], ["sushi", 16], ["japanese"], ["ramen", 16], ["japanese"]]
Output
[null, "kimchi", "ramen", null, "sushi", null, "ramen"]

Explanation
FoodRatings foodRatings = new FoodRatings(["kimchi", "miso", "sushi", "moussaka", "ramen", "bulgogi"], ["korean", "japanese", "japanese", "greek", "japanese", "korean"], [9, 12, 8, 15, 14, 7]);
foodRatings.highestRated("korean"); // return "kimchi"
                                    // "kimchi" is the highest rated korean food with a rating of 9.
foodRatings.highestRated("japanese"); // return "ramen"
                                      // "ramen" is the highest rated japanese food with a rating of 14.
foodRatings.changeRating("sushi", 16); // "sushi" now has a rating of 16.
foodRatings.highestRated("japanese"); // return "sushi"
                                      // "sushi" is the highest rated japanese food with a rating of 16.
foodRatings.changeRating("ramen", 16); // "ramen" now has a rating of 16.
foodRatings.highestRated("japanese"); // return "ramen"
                                      // Both "sushi" and "ramen" have a rating of 16.
                                      // However, "ramen" is lexicographically smaller than "sushi".

 

Constraints:

  • 1 <= n <= 2 * 104
  • n == foods.length == cuisines.length == ratings.length
  • 1 <= foods[i].length, cuisines[i].length <= 10
  • foods[i], cuisines[i] consist of lowercase English letters.
  • 1 <= ratings[i] <= 108
  • All the strings in foods are distinct.
  • food will be the name of a food item in the system across all calls to changeRating.
  • cuisine will be a type of cuisine of at least one food item in the system across all calls to highestRated.
  • At most 2 * 104 calls in total will be made to changeRating and highestRated.
4. Longest Valid Parentheses Substring Length
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.

 

Example 1:

Input: s = "(()"
Output: 2
Explanation: The longest valid parentheses substring is "()".

Example 2:

Input: s = ")()())"
Output: 4
Explanation: The longest valid parentheses substring is "()()".

Example 3:

Input: s = ""
Output: 0

 

Constraints:

  • 0 <= s.length <= 3 * 104
  • s[i] is '(', or ')'.
5. In-Memory File System Design
Design a data structure that simulates an in-memory file system.

Implement the FileSystem class:

  • FileSystem() Initializes the object of the system.
  • List<String> ls(String path)
    • If path is a file path, returns a list that only contains this file's name.
    • If path is a directory path, returns the list of file and directory names in this directory.
  • The answer should in lexicographic order.
  • void mkdir(String path) Makes a new directory according to the given path. The given directory path does not exist. If the middle directories in the path do not exist, you should create them as well.
  • void addContentToFile(String filePath, String content)
    • If filePath does not exist, creates that file containing given content.
    • If filePath already exists, appends the given content to original content.
  • String readContentFromFile(String filePath) Returns the content in the file at filePath.
 

Example 1:

Input
["FileSystem", "ls", "mkdir", "addContentToFile", "ls", "readContentFromFile"]
[[], ["/"], ["/a/b/c"], ["/a/b/c/d", "hello"], ["/"], ["/a/b/c/d"]]
Output
[null, [], null, null, ["a"], "hello"]

Explanation
FileSystem fileSystem = new FileSystem();
fileSystem.ls("/");                         // return []
fileSystem.mkdir("/a/b/c");
fileSystem.addContentToFile("/a/b/c/d", "hello");
fileSystem.ls("/");                         // return ["a"]
fileSystem.readContentFromFile("/a/b/c/d"); // return "hello"

 

Constraints:

  • 1 <= path.length, filePath.length <= 100
  • path and filePath are absolute paths which begin with '/' and do not end with '/' except that the path is just "/".
  • You can assume that all directory names and file names only contain lowercase letters, and the same names will not exist in the same directory.
  • You can assume that all operations will be passed valid parameters, and users will not attempt to retrieve file content or list a directory or file that does not exist.
  • 1 <= content.length <= 50
  • At most 300 calls will be made to ls, mkdir, addContentToFile, and readContentFromFile.