Anthropic software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
Description Sampling profilers capture the call stack at periodic intervals to analyze program performance. However, most trace visualization tools...
Input: ListDescription Given a list of file paths in a directory system, find all duplicate files. Two files are considered duplicates if they have identical...
Input: Listtext and a dictionary array where each element is in the format "<key>:<id>". Here key is a token string and id...Input: Arrayclass Bank: def __init__(self) -> None: def create_account(self, account_id: str) -> None: def deposit(self, account_id: str, amount: float) -> None: def withdraw(self, account_id: str, amount: float) -> bool: def transfer(self, from_account: str, to_account: str, amount: float) -> bool: bank = Bank() bank.create_account('123') bank.deposit('123', 200.0) bank.withdraw('123', 50.0) 150.0 (balance after the operations) bank.create_account('123') bank.create_account('456') bank.deposit('123', 300.0) bank.transfer('123', '456', 150.0) (True, 150.0) (Transfer was successful, remaining balance for 123 is 150.0) 1 ≤ account_id.length ≤ 100 amount ≥ 0 BankingSystem class that allows for concurrent deposits and withdrawals. The system must ensure thread-safety so that operations do not conflict. Implement the following methods in the class: deposit(accountId: int, amount: float) -> None: Increases the balance of the specified account by the given amount. withdraw(accountId: int, amount: float) -> bool: Decreases the balance by the specified amount if sufficient funds are available; returns True if successful, otherwise False. get_balance(accountId: int) -> float: Returns the current balance of the specified account. class BankingSystem: def deposit(accountId: int, amount: float) -> None def withdraw(accountId: int, amount: float) -> bool def get_balance(accountId: int) -> float bs = BankingSystem() bs.deposit(1, 500.0) bs.withdraw(1, 200.0) bs.get_balance(1)
300.0 bs.withdraw(1, 400.0)
False accountId ≤ 10000 amount ≤ 10000 n accounts with the most total transactions (both deposits and withdrawals). Function/class signature: class Bank: def create_account(self, account_id: int) -> None: def deposit(self, account_id: int, amount: float) -> None: def withdraw(self, account_id: int, amount: float) -> bool: def get_total_transactions(self, account_id: int) -> float: def get_top_accounts(self, n: int) -> List[int]: bank = Bank() bank.create_account(1) bank.deposit(1, 100) bank.withdraw(1, 50) bank.create_account(2) bank.deposit(2, 200) bank.deposit(2, 80) bank.get_top_accounts(1)
[2] 2 has the highest total transactions (280). Example 2: bank.create_account(3) bank.deposit(3, 150) bank.withdraw(3, 30) bank.get_top_accounts(2)
[2, 3] 2 has (280) and account 3 has (120) total transactions.Constraints: 1 <= account_id <= 10^4 0 <= amount <= 10^6 1 <= n <= 100 nums, return the maximum number of consecutive 1s in the array. For example, in the array [1,1,0,1,1,1], the longest consecutive sequence of 1s is 3. Your function should handle large inputs and provide results quickly, as this operation could be part of a larger data analysis framework.Function/class signature: def findMaxConsecutiveOnes(nums: List[int]) -> int:findMaxConsecutiveOnes([1,1,0,1,1,1]) 3 1s is 111.Example 2: findMaxConsecutiveOnes([1,0,1,1,0,1]) 2 1s is 11.Constraints: 1 <= nums.length <= 10^5 nums[i] is either 0 or 1. class BankingSystem:def create_account(self, account_id: int) -> None:def transfer(self, from_account: int, to_account: int, amount: float, schedule_time: datetime) -> bool:def get_balance(self, account_id: int) -> float:Example 1: create_account(1) create_account(2) transfer(1, 2, 100, datetime(2023, 10, 1, 10, 0)) True transfer(1, 2, 50, datetime(2023, 10, 1, 10, 0)) False set(file: str, data: bytes) -> None to store a file.get(file: str) -> Optional[bytes] to retrieve file data by name.filter(criteria: Callable[[str], bool]) -> List[str] to return a list of files matching certain conditions.backup(destination: str) -> None to backup all files to a specified location.restore(source: str) -> None to restore files from a backup location.Class API:set(file: str, data: bytes) -> None: Stores the file file with the content data in bytes.get(file: str) -> Optional[bytes]: Returns the content of the file if it exists, otherwise returns None.filter(criteria: Callable[[str], bool]) -> List[str]: Returns a list of file names that match the given criteria.backup(destination: str) -> None: Backs up the current files to the specified destination.restore(source: str) -> None: Restores files from a backup source.set('document.txt', b'This is a document.') set('image.png', b'Image data here.') get('document.txt') returns b'This is a document.' filter(lambda x: x.endswith('.png')) returns ['image.png'] set is used to store files and get retrieves the content of a specific file. The filter method uses a lambda function to find files with the .png extension.Example 2: backup('/backup/location') restore('/backup/location') Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free