Pinterest计算机科学面试真题

职位分类
全部
数据相关
计算机科学
人工智能
产品经理
BQ
面试题
全部(10)
OOD(1)
Algorithm(9)
System Design(0)
高频题(0)
Math(0)
全部(10)
OOD(1)
Algorithm(9)
System Design(0)
高频题(0)
Math(0)
1.Count and Say Sequence Algorithm
2.Employee Free Time Calculation
3.Algorithm to Ensure Non-Adjacent Elements Are Not the Same
4.Expression Evaluation with Operator Precedence
5.Evaluate Expression to Target
6.Monitor Screen Pins Arrangement
7.What is your most proud project?
8.Implement a Trie
9.Combination of Operations to Reach Target
10.Count Unique Objects in 2D Array
1. Count and Say Sequence Algorithm
The count-and-say sequence is a sequence of digit strings defined by the recursive formula:

  • countAndSay(1) = "1"
  • countAndSay(n) is the way you would "say" the digit string from countAndSay(n-1), which is then converted into a different digit string.
To determine how you "say" a digit string, split it into the minimal number of substrings such that each substring contains exactly one unique digit. Then for each substring, say the number of digits, then say the digit. Finally, concatenate every said digit.

For example, the saying and conversion for digit string "3322251":

Given a positive integer n, return the nth term of the count-and-say sequence.

 

Example 1:

Input: n = 1
Output: "1"
Explanation: This is the base case.

Example 2:

Input: n = 4
Output: "1211"
Explanation:
countAndSay(1) = "1"
countAndSay(2) = say "1" = one 1 = "11"
countAndSay(3) = say "11" = two 1's = "21"
countAndSay(4) = say "21" = one 2 + one 1 = "12" + "11" = "1211"

 

Constraints:

  • 1 <= n <= 30
2. Employee Free Time Calculation
 We are given a list schedule of employees, which represents the working time for each employee.

Each employee has a list of non-overlapping Intervals, and these intervals are in sorted order.

Return the list of finite intervals representing common, positive-length free time for all employees, also in sorted order.

(Even though we are representing Intervals in the form [x, y], the objects inside are Intervals, not lists or arrays. For example, schedule[0][0].start = 1, schedule[0][0].end = 2, and schedule[0][0][0] is not defined).  Also, we wouldn't include intervals like [5, 5] in our answer, as they have zero length.

 

Example 1:

Input: schedule = [[[1,2],[5,6]],[[1,3]],[[4,10]]] 
Output: [[3,4]] 
Explanation: There are a total of three employees, and all common free time intervals would be [-inf, 1], [3, 4], [10, inf]. We discard any intervals that contain inf as they aren't finite. 

Example 2:

Input: schedule = [[[1,3],[6,7]],[[2,4]],[[2,5],[9,12]]] 
Output: [[5,6],[7,9]] 

 

Constraints:

1 <= schedule.length , schedule[i].length <= 50

0 <= schedule[i].start < schedule[i].end <= 10^8
3. Algorithm to Ensure Non-Adjacent Elements Are Not the Same
Given an input list, write an algorithm to output a list where adjacent elements are not the same. If it is not possible, output the largest possible list. For example, given the input list [a, a, b, a], the output should be [a, b, a]. Additionally, discuss how you would handle extremely large inputs.
4. Expression Evaluation with Operator Precedence
Based on the previous problem, how would you handle the evaluation of an expression if the order of operations needs to be considered? For instance, if multiplication appears later in the list, it must be calculated before the addition that comes before it.
5. Evaluate Expression to Target
Given an integer list, evaluate the expression by adding or multiplying the elements from left to right, with the operations being evaluated as they appear. Determine if the result equals the target. For the follow-up, consider how you would handle the introduction of subtraction and division, taking into account the presence of zero or negative numbers.