Pinterest计算机科学面试真题

职位分类
全部
数据相关
计算机科学
人工智能
产品经理
BQ
面试题
全部(4)
OOD(0)
Algorithm(4)
System Design(0)
高频题(0)
Math(0)
全部(4)
OOD(0)
Algorithm(4)
System Design(0)
高频题(0)
Math(0)
1.Count and Say Sequence Algorithm
2.Employee Free Time Calculation
3.Combination of Operations to Reach Target
4.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. Combination of Operations to Reach Target
Given a list of numbers and a target value, determine if it is possible to obtain the target by performing a sequence of addition or multiplication operations from left to right on the numbers. You may also consider starting the operations from the end of the list and working backwards to find a new target at each step.
4. Count Unique Objects in 2D Array
Given an `isSameObject` API that returns true only if two elements in a 2D array are the same object and are connected, write a function to determine the number of unique objects (pins) in the array. For example, given the following 2D array: ["" , "x", "y"] ["z", "x", "y"] ["", "x", ""] Your function should return 3, as there are three unique objects. Note that the `isSameObject` API returns false for comparisons with blank spaces. Explain your approach and discuss the time and space complexity of your solution.