Salesforce software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
No verified questions yet for Salesforce.
(a, b) indicates a connection between contacts a and b, your task is to find the total number of distinct leads reachable from a given starting contact.Method Signature:def countUniqueLeads(contacts: List[Tuple[int, int]], start: int) -> int:Example 1:contacts = [(1, 2), (2, 3), (3, 4)], start = 14contacts = [(1, 2), (2, 3), (3, 4), (5, 6)], start = 521 <= len(contacts) <= 10^51 <= contacts[i][0], contacts[i][1] <= 10^6int timestamps representing the arrival times of API requests and an integer windowSize, your task is to determine the maximum number of API requests that can be handled within any windowSize seconds.Method Signature:def maxRequestsWithinWindow(timestamps: List[int], windowSize: int) -> int:Example 1:timestamps = [1, 2, 3, 5, 6]4timestamps = [1, 3, 6, 8, 10]31 <= len(timestamps) <= 10^50 <= windowSize <= 10^60 <= timestamps[i] <= 10^6class EventLogger:def log(eventType: str, timestamp: int) -> None: — Records an event with its type and the time it occurred.def getLogs(eventType: str, startTime: int, endTime: int) -> List[Tuple[str, int]]: — Retrieves events of a specific type that occurred between the given start and end time.Example 1:logger = EventLogger(), logger.log('login', 1), logger.log('logout', 2), logger.getLogs('login', 0, 5)[('login', 1)]logger.log('click', 3), logger.getLogs('click', 1, 4)[('click', 3)]1 <= eventType.length <= 1000 <= timestamp <= 10^9class LRUCache:def __init__(self, capacity: int): — Initializes the LRUCache with a positive size capacity.def get(self, key: int) -> int: — Returns the value of the key if the key exists, otherwise returns -1.def put(self, key: int, value: int) -> None: — Updates the value of the key if the key exists, otherwise adds the key-value pair to the cache.LRUCache(2), cache.put(1, 1), cache.put(2, 2), cache.get(1)1 (returns the value of key 1)Example 2:cache.put(3, 3) (evicts key 2) then cache.get(2)-1 (key 2 was evicted)Constraints:1 <= capacity <= 30000 <= key <= 10^40 <= value <= 10^4Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free