Linkedin计算机科学面试真题

职位分类
全部
数据相关
计算机科学
人工智能
产品经理
BQ
面试题
全部(58)
OOD(1)
Algorithm(55)
System Design(2)
高频题(9)
Math(0)
全部(58)
OOD(1)
Algorithm(55)
System Design(2)
高频题(9)
Math(0)
1.Max Points on a Line
2.Can New Flowers Be Planted Without Adjacency Violation?
3.Design and Implement AllOne Data Structure with Min-Max String Count Operations
4.Max Profit with K Stock Transactions
5.Max Points on a Line
6.Exclusive Time of Functions
7.Finding the Lowest Common Ancestor of Two Nodes in a Binary Tree
8.BinarySearchTreeSerializationAndDeserialization
9.Word Ladder Transformation Sequence Length
10.Serialize and Deserialize Binary Search Tree Algorithm
11.Designing Binary Tree Serialization and Deserialization Algorithm
12.Lowest Common Ancestor of a Binary Tree with Parent Pointers
13.Valid Parenthesis String with Asterisks
14."Collecting Nodes from Binary Tree by Removing Leaves in Layers"
15.Check if Number is a Perfect Square Without Using sqrt Function
16.Implementing Power Function in Python
17.Base Negative Two Number Representation
18.Next Greater Node In Linked List
19.Can New Flowers Be Planted Without Adjacency Violation?
20."Finding Maximum Depth of a Binary Tree"
21.Valid Parentheses String Checker
22.Maximum Product Subarray
23.Counting Number of Islands in a 2D Grid
24.String Replacement with Indexed Substrings
25."Check if Undirected Graph is a Valid Tree"
26.Design and Implement a Custom HashMap in Java
27."Maximum Area of an Island in a Binary Matrix"
28.Minimum Operations to Remove All Ones from Binary Matrix
29.Finding the Lowest Common Ancestor in a Binary Search Tree
30.Shortest Word Distance in Array Data Structure
31.Minimum Insertions to Make a String Palindrome
32.Factor Combinations of an Integer
33.Nested Integer Weight Sum
34.Validating Scientific Notation Numbers
35.LRU Cache Implementation and Usage Example
36.文件删除
37.Upside Down Binary Tree Transformation
38.Valid Parentheses String Checker
39.Insert and Merge Intervals
40.Implement strStr() Function in String
41.Design RandomizedSet Class with O(1) Operations
42.Design and Implement an All-In-One Data Structure for String Frequency Tracking
43."Rotate Linked List by K Places"
44.Search in Rotated Sorted Array
45.Longest Palindrome by Rearranging Letters
46.Finding the Minimum Element in a Rotated Sorted Array
47."Valid Parentheses String Checker"
48.Merge k Sorted Lists
49.Design RandomizedSet and RandomizedCollection Classes
50.Subarray Sum Equals K and K Smallest Pairs from Two Sorted Arrays
51.Design and Implement a Max Stack Data Structure
52.DesignRandomizedSetAndRandomizedCollectionClasses
53.Counting Number of Ones in Integers Less Than or Equal to N
54.Find First and Last Position of Element in Sorted Array
55.Closest Binary Search Tree Value
56.Maximum Subarray
57.Find K Closest Points to Origin
58.Print node by level
1. Max Points on a Line
Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane, return the maximum number of points that lie on the same straight line.

 

Example 1:

Input: points = [[1,1],[2,2],[3,3]]
Output: 3

Example 2:

Input: points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]
Output: 4

 

Constraints:

  • 1 <= points.length <= 300
  • points[i].length == 2
  • -104 <= xi, yi <= 104
  • All the points are unique.
2. Can New Flowers Be Planted Without Adjacency Violation?
You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots.

Given an integer array flowerbed containing 0's and 1's, where 0 means empty and 1 means not empty, and an integer n, return if n new flowers can be planted in the flowerbed without violating the no-adjacent-flowers rule.

 

Example 1:

Input: flowerbed = [1,0,0,0,1], n = 1
Output: true

Example 2:

Input: flowerbed = [1,0,0,0,1], n = 2
Output: false

 

Constraints:

  • 1 <= flowerbed.length <= 2 * 104
  • flowerbed[i] is 0 or 1.
  • There are no two adjacent flowers in flowerbed.
  • 0 <= n <= flowerbed.length
3. Design and Implement AllOne Data Structure with Min-Max String Count Operations
Design a data structure to store the strings' count with the ability to return the strings with minimum and maximum counts.

Implement the AllOne class:

  • AllOne() Initializes the object of the data structure.
  • inc(String key) Increments the count of the string key by 1. If key does not exist in the data structure, insert it with count 1.
  • dec(String key) Decrements the count of the string key by 1. If the count of key is 0 after the decrement, remove it from the data structure. It is guaranteed that key exists in the data structure before the decrement.
  • getMaxKey() Returns one of the keys with the maximal count. If no element exists, return an empty string "".
  • getMinKey() Returns one of the keys with the minimum count. If no element exists, return an empty string "".
Note that each function must run in O(1) average time complexity.

 

Example 1:

Input
["AllOne", "inc", "inc", "getMaxKey", "getMinKey", "inc", "getMaxKey", "getMinKey"]
[[], ["hello"], ["hello"], [], [], ["leet"], [], []]
Output
[null, null, null, "hello", "hello", null, "hello", "leet"]

Explanation
AllOne allOne = new AllOne();
allOne.inc("hello");
allOne.inc("hello");
allOne.getMaxKey(); // return "hello"
allOne.getMinKey(); // return "hello"
allOne.inc("leet");
allOne.getMaxKey(); // return "hello"
allOne.getMinKey(); // return "leet"

 

Constraints:

  • 1 <= key.length <= 10
  • key consists of lowercase English letters.
  • It is guaranteed that for each call to dec, key is existing in the data structure.
  • At most 5 * 104 calls will be made to inc, dec, getMaxKey, and getMinKey.
4. Max Profit with K Stock Transactions
You are given an integer array prices where prices[i] is the price of a given stock on the ith day, and an integer k.

Find the maximum profit you can achieve. You may complete at most k transactions.

Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).

 

Example 1:

Input: k = 2, prices = [2,4,1]
Output: 2
Explanation: Buy on day 1 (price = 2) and sell on day 2 (price = 4), profit = 4-2 = 2.

Example 2:

Input: k = 2, prices = [3,2,6,5,0,3]
Output: 7
Explanation: Buy on day 2 (price = 2) and sell on day 3 (price = 6), profit = 6-2 = 4. 
Then buy on day 5 (price = 0) and sell on day 6 (price = 3), profit = 3-0 = 3.

 

Constraints:

  • 0 <= k <= 100
  • 0 <= prices.length <= 1000
  • 0 <= prices[i] <= 1000
5. Max Points on a Line
Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane, return the maximum number of points that lie on the same straight line.

 

Example 1:

Input: points = [[1,1],[2,2],[3,3]]
Output: 3

Example 2:

Input: points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]
Output: 4

 

Constraints:

  • 1 <= points.length <= 300
  • points[i].length == 2
  • -104 <= xi, yi <= 104
  • All the points are unique.