<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-KVGHS6G" height="0" width="0" style="display:none;visibility:hidden"></iframe>

Snapchat计算机科学面试真题

职位分类
全部
数据相关
计算机科学
人工智能
产品经理
BQ
面试题
全部(60)
OOD(4)
Algorithm(32)
System Design(24)
高频题(0)
Math(0)
全部(60)
OOD(4)
Algorithm(32)
System Design(24)
高频题(0)
Math(0)
1.Merge K Sorted Linked Lists
2.Course Schedule II
3.Course Schedule Feasibility Check
4.Shortest Path in a Grid with Obstacles Elimination
5.Word Search II on a Board
6.Car Fleet Problem
7.Reading item
8.到河对岸的最短距离
9.Next Highest Number
10.Cheapest Flights Within K Stops
11.Course Schedule Feasibility Check
12.Implement a Rate Limiter
13.Implement a Simplified Serializer
14.Find Non-Friend Pairs
15.Minimum Cost to Retrieve Complete File from Multiple Machines
16.Coding Question: Course Schedule Problem
17.Design a Typeahead System
18.Design a Job Scheduler
19.Design an Advertisement Targeting System
20.Design an E-commerce Home Page
21.Design a Password Login Application
22.Design a Rate Limiter
23.Design Instagram Stories Feature
24.Design a Message Queue
25.Implement Video Playback Memory Feature
26.Design an Access Control System
27.Design a Social Media Platform
28.Design an Advertisement Recommendation System for a Feed
29.Design a Snapchat Video Recommendation System
30.Design a Company Personnel System
31.Design Add and Delete Sticker Features
32.Design a Simplified Version of YouTube
33.Matrix Movement Optimization Problem
34.Find all the lowest-priced paths between two places given a list of network connections.
35.Design an XML Parser
36.Optimize Airfare Search with Dijkstra's Algorithm and Limited Connecting Flights
37.Algorithm Design: Message Processing System
38.Implement a Topological Sort to Print an Indented Employee Hierarchy
39.Decode String
40.Next Greater Element
41.Number of Islands
42.Resource Allocator System Design
43.Matrix Path with Minimum Elevation Difference
44.Find the longest consecutive sequence in O(n) time
45.Design an A/B testing framework
46.Design a system for sending messages with a page for selecting recipients
47.Word Search in a Grid
48.C++ Coding: Modify String
49.C++ Debugging: Code Review
50.C++ Knowledge: Smart Pointers
51.DFS for JSON Structure
52.System Design for Recommending Snap Filters
53.System Design for Video Home Feed
54.Maze Solving with Limited Drill Usage
55.System Design
56.Most Frequent User Location in Past 30 Days
57.Lowest Cost Path in a Directed Graph with Values
58.Skyline Problem
59.Merge Intervals
60.Implement a function without using stack
1. Merge K Sorted Linked Lists
You are given an array of k linked-lists lists, each linked-list is sorted in ascending order.

Merge all the linked-lists into one sorted linked-list and return it.

 

Example 1:

Input: lists = [[1,4,5],[1,3,4],[2,6]]
Output: [1,1,2,3,4,4,5,6]
Explanation: The linked-lists are:
[
  1->4->5,
  1->3->4,
  2->6
]
merging them into one sorted list:
1->1->2->3->4->4->5->6

Example 2:

Input: lists = []
Output: []

Example 3:

Input: lists = [[]]
Output: []

 

Constraints:

  • k == lists.length
  • 0 <= k <= 104
  • 0 <= lists[i].length <= 500
  • -104 <= lists[i][j] <= 104
  • lists[i] is sorted in ascending order.
  • The sum of lists[i].length will not exceed 104.
2. Course Schedule II
There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai.

  • For example, the pair [0, 1], indicates that to take course 0 you have to first take course 1.
Return the ordering of courses you should take to finish all courses. If there are many valid answers, return any of them. If it is impossible to finish all courses, return an empty array.

 

Example 1:

Input: numCourses = 2, prerequisites = [[1,0]]
Output: [0,1]
Explanation: There are a total of 2 courses to take. To take course 1 you should have finished course 0. So the correct course order is [0,1].

Example 2:

Input: numCourses = 4, prerequisites = [[1,0],[2,0],[3,1],[3,2]]
Output: [0,2,1,3]
Explanation: There are a total of 4 courses to take. To take course 3 you should have finished both courses 1 and 2. Both courses 1 and 2 should be taken after you finished course 0.
So one correct course order is [0,1,2,3]. Another correct ordering is [0,2,1,3].

Example 3:

Input: numCourses = 1, prerequisites = []
Output: [0]

 

Constraints:

  • 1 <= numCourses <= 2000
  • 0 <= prerequisites.length <= numCourses * (numCourses - 1)
  • prerequisites[i].length == 2
  • 0 <= ai, bi < numCourses
  • ai != bi
  • All the pairs [ai, bi] are distinct.
3. Course Schedule Feasibility Check
There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai.

  • For example, the pair [0, 1], indicates that to take course 0 you have to first take course 1.
Return true if you can finish all courses. Otherwise, return false.

 

Example 1:

Input: numCourses = 2, prerequisites = [[1,0]]
Output: true
Explanation: There are a total of 2 courses to take. 
To take course 1 you should have finished course 0. So it is possible.

Example 2:

Input: numCourses = 2, prerequisites = [[1,0],[0,1]]
Output: false
Explanation: There are a total of 2 courses to take. 
To take course 1 you should have finished course 0, and to take course 0 you should also have finished course 1. So it is impossible.

 

Constraints:

  • 1 <= numCourses <= 2000
  • 0 <= prerequisites.length <= 5000
  • prerequisites[i].length == 2
  • 0 <= ai, bi < numCourses
  • All the pairs prerequisites[i] are unique.
4. Shortest Path in a Grid with Obstacles Elimination
You are given an m x n integer matrix grid where each cell is either 0 (empty) or 1 (obstacle). You can move up, down, left, or right from and to an empty cell in one step.

Return the minimum number of steps to walk from the upper left corner (0, 0) to the lower right corner (m - 1, n - 1) given that you can eliminate at most k obstacles. If it is not possible to find such walk return -1.

 

Example 1:

Input: grid = [[0,0,0],[1,1,0],[0,0,0],[0,1,1],[0,0,0]], k = 1
Output: 6
Explanation: 
The shortest path without eliminating any obstacle is 10.
The shortest path with one obstacle elimination at position (3,2) is 6. Such path is (0,0) -> (0,1) -> (0,2) -> (1,2) -> (2,2) -> (3,2) -> (4,2).

Example 2:

Input: grid = [[0,1,1],[1,1,1],[1,0,0]], k = 1
Output: -1
Explanation: We need to eliminate at least two obstacles to find such a walk.

 

Constraints:

  • m == grid.length
  • n == grid[i].length
  • 1 <= m, n <= 40
  • 1 <= k <= m * n
  • grid[i][j] is either 0 or 1.
  • grid[0][0] == grid[m - 1][n - 1] == 0
5. Word Search II on a Board
Given an m x n board of characters and a list of strings words, return all words on the board.

Each word must be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once in a word.

 

Example 1:

Input: board = [["o","a","a","n"],["e","t","a","e"],["i","h","k","r"],["i","f","l","v"]], words = ["oath","pea","eat","rain"]
Output: ["eat","oath"]

Example 2:

Input: board = [["a","b"],["c","d"]], words = ["abcb"]
Output: []

 

Constraints:

  • m == board.length
  • n == board[i].length
  • 1 <= m, n <= 12
  • board[i][j] is a lowercase English letter.
  • 1 <= words.length <= 3 * 104
  • 1 <= words[i].length <= 10
  • words[i] consists of lowercase English letters.
  • All the strings of words are unique.