Home

Roman to Integer

13. Roman to Integer Solution - Cleaner Solution Reference If one letter is less than its latter one, this letter is subtracted. Always remember to add the last letter. def romanToInt(self, s): roman = {'M': 1000,'D': 500 ,'C': 100,'L': 50,'X': 10,'V': 5,'I': 1} z = 0 for i in range(0, len(s) - 1): if roman[s[i]] &...

Read more

Best Time to Buy and Sell Stock II

122. Best Time to Buy and Sell Stock II Solution Keep a strictly increasing stack. When a decreased element come in, add the profit that can be earned from the stack, and clean up the stack. def maxProfit(self, prices): """ :type prices: List[int] :rtype: int """ stack = [] profit = 0 for p in p...

Read more

Special Array With X Elements Greater Than or Equal X

1608. Special Array With X Elements Greater Than or Equal X You are given an array nums of non-negative integers. nums is considered special if there exists a number x such that there are exactly x numbers in nums that are greater than or equal to x. Notice that x does not have to be an element in nums. Return x if the array is special, otherw...

Read more

Maximum Number of Visible Points

1610. Maximum Number of Visible Points You are given an array points, an integer angle, and your location, where location = [posx, posy] and points[i] = [xi, yi] both denote integral coordinates on the X-Y plane. Initially, you are facing directly east from your position. You cannot move from your position, but you can rotate. In other words, p...

Read more

Even Odd Tree

1609. Even Odd Tree A binary tree is named Even-Odd if it meets the following conditions: The root of the binary tree is at level index 0, its children are at level index 1, their children are at level index 2, etc. For every even-indexed level, all nodes at the level have odd integer values in strictly increasing order (from left to right). Fo...

Read more

Find Valid Matrix Given Row and Column Sums

1605. Find Valid Matrix Given Row and Column Sums You are given two arrays rowSum and colSum of non-negative integers where rowSum[i] is the sum of the elements in the ith row and colSum[j] is the sum of the elements of the jth column of a 2D matrix. In other words, you do not know the elements of the matrix, but you do know the sums of each row...

Read more

Find Servers That Handled Most Number of Requests

1606. Find Servers That Handled Most Number of Requests You have k servers numbered from 0 to k-1 that are being used to handle multiple requests simultaneously. Each server has infinite computational capacity but cannot handle more than one request at a time. The requests are assigned to servers according to a specific algorithm: The ith (0-in...

Read more

Design Parking System

1603. Design Parking System Design a parking system for a parking lot. The parking lot has three kinds of parking spaces: big, medium, and small, with a fixed number of slots for each size. Implement the ParkingSystem class: ParkingSystem(int big, int medium, int small) Initializes object of the ParkingSystem class. The number of slots for eac...

Read more