Square software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
Question Design a ConnectFour class that implements the Connect Four board game. The board is a 6-row by 7-column grid. Two players take turns...
Question Design a PageNavigator class that simulates a paginated view with a sliding window. Given a total number of pages and a window size, the...
Question You are given a 2D grid containing open cells (".") and walls ("#"). An exit is any open cell on the border of the grid that is...
Question Design an ItemPriceManager class that tracks the price history of an item over time and supports querying the price at any date and the...
Question Translate a sentence into Pig Latin using the following rules: Rules: 1. If a word begins with a vowel (a, e, i, o, u),...
Question Given a string, build a Frequency Merge Tree as follows: 1. Count the frequency of each character in the string. 2. Create a leaf node...
Input: StringQuestion You are given two integers R and C representing the number of rows and columns in a grid (0-indexed). You are also given a list...
Question
Input: Array of stringsQuestion
Input: Array of stringsx, implement a function that returns the integer part of the square root of x. The square root is defined as the number y such that y * y <= x < (y + 1) * (y + 1). You should implement this using binary search.def my_sqrt(x: int) -> int:x = 828 is 2.828..., so the integer part is 2.x = 16416 is 4.0 <= x <= 2 * 10^9nums, representing transaction IDs, and an integer k, return the k most frequent elements. You need to implement the function topKFrequent(nums: List[int], k: int) -> List[int].def topKFrequent(nums: List[int], k: int) -> List[int]:nums = [1,1,1,2,2,3], k = 2[1, 2]1 appears three times, while 2 appears twice. Therefore, the top two frequent elements are 1 and 2.nums = [1], k = 1[1]1, it is the only frequent element.1 <= nums.length <= 10^50 <= nums[i] < 10^41 <= k <= number of unique elements in the arraysend_notification(user_id: str, message: str, notification_type: str) -> bool set_preferences(user_id: str, preferences: dict) -> None get_status(notification_id: str) -> dict flush_queue() -> None send_notification('userA', 'Your payment was successful!', 'email') → Output: True → Explanation: The notification is queued successfully.Example 2: set_preferences('userA', {'email': False, 'SMS': True}) → Output: None → Explanation: User preferences are updated without error.Constraints: add_payment_method(method: str) -> None: Adds a new payment method to be supported.process_payment(transaction_id: str, amount: float, method: str) -> str: Processes a payment and returns the transaction status.get_transaction_status(transaction_id: str) -> str: Retrieves the status of a given transaction.get_transaction_history() -> List[Dict[str, Any]]: Returns a list of all transactions.add_payment_method("Credit Card") → Output: None → Explanation: Adds "Credit Card" as a valid payment method.process_payment("txn_123", 100.00, "Credit Card") → Output: "Success" → Explanation: Processes a payment for 100.00 using the credit card method.class BankAccount: - represents an individual user account.def __init__(self, account_id: str, initial_balance: float) -> None: - initializes a new account with a unique ID and balance.def deposit(self, amount: float) -> str: - deposits a specified amount into the account.def withdraw(self, amount: float) -> str: - withdraws a specified amount from the account.def get_balance(self) -> float: - returns the current balance of the account.Example 1:account = BankAccount('12345', 100.0); account.deposit(50.0); account.withdraw(30.0)account.get_balance() → 120.0account = BankAccount('67890', 200.0); account.withdraw(250.0)account.get_balance() → 200.0account_id must be a unique string.initial_balance must be a non-negative float.amount for deposits and withdrawals must be a positive float.class User: Represents a bank user.def __init__(self, user_id: str, name: str) -> None: Initializes a new user with ID and name.def deposit(self, amount: float) -> None: Deposits a specified amount into the user's account.def withdraw(self, amount: float) -> None: Withdraws a specified amount from the user's account.class Transaction: Represents a transaction in the banking system.def __init__(self, user_id: str, amount: float, type: str) -> None: Initializes a new transaction with user ID, amount, and type (deposit/withdraw).class Bank: Main class for interaction.def create_user(self, name: str) -> User: Creates a new user.def transfer(self, from_user: User, to_user: User, amount: float) -> None: Transfers funding between users.Example 1:Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free