Snapchat software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
s. The expression may contain positive and negative integers, the...Input: Stringprimes where every element is a prime number (duplicates are allowed), find all distinct products that can be formed by multiplying...Input: Array. for an ordinary walkable cell, # for a barrier, or R for a restaurant. Starting at start, you may move one cell up, down, left, or right. Every move costs one unit of walking distance.A route may enter at most budget barrier cells. Each move into a # cell consumes one unit of that route's budget, including repeated entries into the same barrier. Moving out of a barrier into a non-barrier cell consumes no budget. The budget applies independently to each candidate route: you are finding nearby destinations, not planning one trip that visits every restaurant.Return up to k reachable restaurants as records with integer fields row, col, and distance. A restaurant's distance is the minimum number of moves among all routes that respect the budget. Return each restaurant only once, ordered by distance ascending, then row ascending, then column ascending. If the starting cell is a restaurant, its distance is zero. Restaurants may be traversed like ordinary walkable cells.Your implementation must avoid enumerating individual routes. In particular, explain why marking a grid coordinate as visited without considering the remaining crossing budget can produce an incorrect answer.Function or class signaturenearest_restaurants(grid: list[str], start: tuple[int, int], k: int, budget: int) -> list[dict[str, int]]{"grid":[".R#R.",".###.","R...R"],"start":[0,0],"k":3,"budget":1}Output:[{"row":0,"col":1,"distance":1},{"row":2,"col":0,"distance":2},{"row":0,"col":3,"distance":3}]Explanation: The first two restaurants require no barrier crossings. The route (0,0) → (0,1) → (0,2) → (0,3) reaches the third restaurant in three moves and enters one barrier. The restaurant at (2,4) is reachable in six moves but is outside the nearest three.Example 2:Input:{"grid":["R#R","###","R.R"],"start":[0,0],"k":5,"budget":0}Output:[{"row":0,"col":0,"distance":0}]Explanation: The starting restaurant is included. Both adjacent cells are barriers, so no other restaurant is reachable without crossing a barrier.Constraints:1 <= rows, cols <= 200 and rows * cols <= 40000.., #, or R.start is an in-bounds coordinate containing . or R.0 <= budget <= 30.0 <= k <= rows * cols; return an empty list when k == 0.Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free