Pinterest software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
CompressedGrid class that stores a sparse integer matrix efficiently by keeping only non-zero values in memory. The class must support...Input: Matrix (2D array)n users numbered from 0 to n - 1. You are given a list of bidirectional friend connections connections, where...Input: ListDirectoryPermissionManager class. The directory hierarchy is...Input: ListGameLevelTracker class. The game...Input: String[start, end] pair. Two meetings overlap if...Input: ListTimedJobQueue. The system accepts jobs with an associated delay and executes them in delay order....Input: List'X' (part of an item) or...Input: 2D gridscores. Each row is sorted in nondecreasing order from left to right, and each column is sorted in nondecreasing order from top to bottom.Return the K largest entries in nonincreasing order. Each matrix cell is a separate entry: equal scores must appear multiple times if multiple such entries belong in the result. Return only score values, not cell coordinates. If k = 0, return an empty list.You must not modify the input matrix or flatten it into another collection. Your algorithm must use O(1) auxiliary space, excluding the returned list, which may also serve as its working buffer. In particular, a separate heap, visited set, or array of row pointers whose size grows with the input is not allowed.Target worst-case time is O((m + n) log(V + 1) + k log(k + 1)), where m and n are the matrix dimensions and V = maximum_score - minimum_score + 1. Standard library sorting is permitted only if its auxiliary-space guarantee meets the requirement.Function or class signaturetop_k_scores(scores: list[list[int]], k: int) -> list[int]{"scores": [[1, 4, 7], [2, 5, 8], [3, 6, 9]], "k": 4}[9, 8, 7, 6]
{"scores": [[-5, -1, 2], [-3, 2, 2], [0, 2, 7]], "k": 3}[7, 2, 2]
1 <= m, n <= 200000, with m * n <= 2000000.scores is rectangular and sorted along both dimensions as specified.[-10^9, 10^9].0 <= k <= min(m * n, 200000).k entries at any point.(score, row, column) triples, ordered by descending score, then ascending row, then ascending column. How would you select entries tied at the cutoff and preserve the same time and auxiliary-space bounds?nums of non-negative integers, partition it into m non-empty contiguous subarrays. The task is to minimize the largest sum among these subarrays. For example, if nums = [7, 2, 5, 10, 8] and m = 2, the partitioning could be [7,2] and [5,10,8], resulting in a largest sum of 18.def split_array(nums: List[int], m: int) -> int:nums = [7, 2, 5, 10, 8], m = 2 18 [7,2] and [5,10,8]. The largest sum is 18.Example 2: nums = [1, 4, 4], m = 3 4 [1], [4], [4], hence the largest sum is 4.Constraints: 1 <= nums.length <= 1000 0 <= nums[i] <= 10^6 1 <= m <= nums.length tickets where each ticket is represented as a pair of strings ['Origin', 'Destination']. You need to reconstruct the itinerary in order of visits starting from 'JFK' and visiting each destination exactly once. The answer should be in lexicographically smallest order if there are multiple valid itineraries. Return the reconstructed itinerary as a list of strings.def find_itinerary(tickets: List[List[str]]) -> List[str]:[['MUC', 'LHR'], ['JFK', 'MUC'], ['SFO', 'SJC'], ['LHR', 'SFO']]['JFK', 'MUC', 'LHR', 'SFO', 'SJC'] [['JFK', 'SFO'], ['JFK', 'ATL'], ['ATL', 'JFK'], ['SFO', 'ATL']]['JFK', 'ATL', 'JFK', 'SFO']Origin and Destination strings consist of uppercase English letters only.def findItinerary(tickets: List[List[str]]) -> List[str]:[['MUC', 'LHR'], ['JFK', 'MUC'], ['SFO', 'SJC'], ['LHR', 'SFO']] ['JFK', 'MUC', 'LHR', 'SFO', 'SJC'] [['JFK', 'SFO'], ['JFK', 'ATL'], ['ATL', 'JFK'], ['SFO', 'ATL']]['JFK', 'ATL', 'JFK', 'SFO']1 <= len(tickets) <= 1000 def reconstruct_itinerary(tickets: List[List[str]]) -> List[str]:[['MUC', 'LHR'], ['JFK', 'MUC'], ['SFO', 'SJC'], ['LHR', 'SFO']]['JFK', 'MUC', 'LHR', 'SFO', 'SJC'][['JFK', 'SFO'], ['JFK', 'ATL'], ['ATL', 'JFK'], ['SFO', 'ATL']]['JFK', 'ATL', 'JFK', 'SFO']1 <= len(tickets) <= 1000(from, to) indicates a direct ticket from from to to, reconstruct the route in the correct order starting from the initial city. You must return a list of cities in the correct order.Function/class signature: def reconstruct_ticket(tickets: List[Tuple[str, str]]) -> List[str]: tickets = [("MUC", "LHR"), ("JFK", "MUC"), ("SFO", "SJC"), ("LHR", "SFO")] ['JFK', 'MUC', 'LHR', 'SFO', 'SJC'] tickets = [("JFK", "ATL"), ("ATL", "JFK"), ("JFK", "SFO")] ['JFK', 'ATL', 'JFK', 'SFO'] 1 ≤ tickets.length ≤ 1000 from and to strings are guaranteed to be non-empty and contain only English letters.def longest_increasing_subsequence(interests: List[int]) -> int:[10, 5, 20, 30, 15] 3 [10, 20, 30].[3, 10, 2, 1, 20] 3 [3, 10, 20].1 <= len(interests) <= 1000 -10^6 <= interests[i] <= 10^6 Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free