"
open = ['(','{','[']
close = [')','}',']']
def is_valid(s: str) -> bool:
pass # your code goes here
n = len(s)
if n == 0:
return True
elif n == 1:
return False
valid = (s[0] == '(' and s[1] == ')') or \
(s[0] == '{' and s[1] == '}') or \
(s[0] == '[' and s[1] == ']')
if valid:
return valid & is_valid(s[2:n])
else :
valid = (s[0] == '(' and s[-1] == ')') or \
(s[0] == '"
Cagdas A. - "
open = ['(','{','[']
close = [')','}',']']
def is_valid(s: str) -> bool:
pass # your code goes here
n = len(s)
if n == 0:
return True
elif n == 1:
return False
valid = (s[0] == '(' and s[1] == ')') or \
(s[0] == '{' and s[1] == '}') or \
(s[0] == '[' and s[1] == ']')
if valid:
return valid & is_valid(s[2:n])
else :
valid = (s[0] == '(' and s[-1] == ')') or \
(s[0] == '"See full answer
"
✅ Passes all test cases:
Tricky:
stock_prices = [1, 10, 2, 3]
output: 9 (Buy on day 1 at 1 and sell on day 2 at 10)
func maxProfit(_ stockPrices: [Int]) -> Int {
var options: [Int] = [] // min-heap
var currentProfit = 0
var maxProfit = 0
for price in stockPrices {
if let cheapestOption = options.last, cheapestOption < price {
if currentProfit < price {
currentProfit += price // greedy profit
} else {
"
Reno S. - "
✅ Passes all test cases:
Tricky:
stock_prices = [1, 10, 2, 3]
output: 9 (Buy on day 1 at 1 and sell on day 2 at 10)
func maxProfit(_ stockPrices: [Int]) -> Int {
var options: [Int] = [] // min-heap
var currentProfit = 0
var maxProfit = 0
for price in stockPrices {
if let cheapestOption = options.last, cheapestOption < price {
if currentProfit < price {
currentProfit += price // greedy profit
} else {
"See full answer
"using a relational database isn't a good choice for this system! we need more availability here than consistency (CAP theorem)"
Anonymous Capybara - "using a relational database isn't a good choice for this system! we need more availability here than consistency (CAP theorem)"See full answer