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 arraySign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free