Brute Force class Solution: def check(self, nums: List[int]) -> bool: """ tc O(N) sc O(1) """ fst = nums[0] end = nums[-1] brk = None inc = True for i in range(1,len(nums)): if nums[i] < nums[i-1]: if inc: brk = nums[i-1] inc = False else: return False # not brk...
[Read More]
LC1727. Largest Submatrix With Rearrangements
```python class Solution: def largestSubmatrix(self, A: List[List[int]]) -> int: “"”tc O(R*ClgC) sc O(C) 1. for each row, its colom’s accumutive height 2. based on current height on one row, sort height, get optimal submatix area 3. compare each row’s max submatrix area, get the max """ r = len(A) c...
[Read More]
LC1656. Design an Ordered Stream
```python
class OrderedStream:
[Read More]
1592. Rearrange Spaces Between Words
class Solution: def reorderSpaces(self, text: str) -> str: """ tc O(N) sc O(M) N: len of text, M: number of words """ cnt = 0 for c in text: if c == ' ': cnt += 1 tmp = text.split() #edge case: there is only one word, unknown space if...
[Read More]
1533. Find the Index of the Large Integer
test case :
[Read More]