"def flatten_dictionary(dictionary):
\# return a flattened dictionary - int/string/another dictionary values
\# if the key is empty, exclude from the output
\# concat using a "." btwn them
\# add to res which is { "key.a.b.etc": "value" }
\# iterate through the key value pairs
\# while there is a key value pair in the value
\# continue going through that, until the value is an int/string
flatDic = {}
flatDicHelper("", dictionary, flatDic)
print(flatDic)
return flatDic
def flatDicHelper(initialKey"
Anonymous Owl - "def flatten_dictionary(dictionary):
\# return a flattened dictionary - int/string/another dictionary values
\# if the key is empty, exclude from the output
\# concat using a "." btwn them
\# add to res which is { "key.a.b.etc": "value" }
\# iterate through the key value pairs
\# while there is a key value pair in the value
\# continue going through that, until the value is an int/string
flatDic = {}
flatDicHelper("", dictionary, flatDic)
print(flatDic)
return flatDic
def flatDicHelper(initialKey"See full answer
"Assuming that trades will have information like
trade_type buy or sell
trade_price
with these tuples, one can iterate over each trade while maintaining a stack which maintains all the open buy trades.
If we encounter a sell trade then we pop one element make it a buy/sell pair and calculate the profit/loss for that pair. Moreover, keep adding pair-wise profit/loss to calculate overall profit as we continue iterating over trades.
At the end print pairs and their profit/loss along with"
Parth S. - "Assuming that trades will have information like
trade_type buy or sell
trade_price
with these tuples, one can iterate over each trade while maintaining a stack which maintains all the open buy trades.
If we encounter a sell trade then we pop one element make it a buy/sell pair and calculate the profit/loss for that pair. Moreover, keep adding pair-wise profit/loss to calculate overall profit as we continue iterating over trades.
At the end print pairs and their profit/loss along with"See full answer
Coding
Data Structures & Algorithms
+1 more
🧠 Want an expert answer to a question? Saving questions lets us know what content to make next.
"WITH CTE AS (
SELECT *, ROWNUMBER()OVER(PARTITION BY utxoid ORDER BY transactionid) AS trxrk
FROM transactions
JOIN transaction_inputs
USING (transaction_id)
JOIN utxo
USING (utxo_id)
)
SELECT transaction_id AS InvalidTransactionId
FROM CTE
WHERE sender!=address OR trx_rk > 1
`"
E L. - "WITH CTE AS (
SELECT *, ROWNUMBER()OVER(PARTITION BY utxoid ORDER BY transactionid) AS trxrk
FROM transactions
JOIN transaction_inputs
USING (transaction_id)
JOIN utxo
USING (utxo_id)
)
SELECT transaction_id AS InvalidTransactionId
FROM CTE
WHERE sender!=address OR trx_rk > 1
`"See full answer
"Sorting is a technique to arrange data in either increasing order or decreasing order, and, the function that implements this functionality is called sort function"
Farhan -. - "Sorting is a technique to arrange data in either increasing order or decreasing order, and, the function that implements this functionality is called sort function"See full answer
"this task is misleading . i used lag(1) and lead(1) cuz it did not say "compare temperature from 2 days before and 1 day before" , it reads to me as if its asking "compare cur temperature to prev and future and see if it rose and fall""
Erjan G. - "this task is misleading . i used lag(1) and lead(1) cuz it did not say "compare temperature from 2 days before and 1 day before" , it reads to me as if its asking "compare cur temperature to prev and future and see if it rose and fall""See full answer
"import random
def coin_flip():
x=4*[0]+[1]
res=[]
for i in range(20):
res.append(random.choice(x))
return res
res=[0,0] # [head,tail]
for j in range(1000):
temp=coin_flip()
res[0]+=sum(temp) #head
res[1]+=(20-sum(temp)) #tail"
Alireza K. - "import random
def coin_flip():
x=4*[0]+[1]
res=[]
for i in range(20):
res.append(random.choice(x))
return res
res=[0,0] # [head,tail]
for j in range(1000):
temp=coin_flip()
res[0]+=sum(temp) #head
res[1]+=(20-sum(temp)) #tail"See full answer
"with cte as
(select *,
row_number() over(order by score desc) as rn
from players)
select player_name, score, rn as ranking
from cte
where rn= 4 or rn =6 or rn =11
`"
Gowtami K. - "with cte as
(select *,
row_number() over(order by score desc) as rn
from players)
select player_name, score, rn as ranking
from cte
where rn= 4 or rn =6 or rn =11
`"See full answer
"def findAlibaba(countOfRooms, strategy):
#countofrooms: num rooms
#listRooms rooms to look for alibabba
possiblePlaces = []
#initialize rooms
for i in range(countOfRooms):
possiblePlaces.append(True)
for i in range(len(strategy)):
roomToCheck = strategy[i]
#Room is marked as unavailable
possiblePlaces[roomToCheck] = False
#Next day calculatins
nextDayPlaces = []
for j in range(countOfRooms):
nextDayPla"
JOBHUNTER - "def findAlibaba(countOfRooms, strategy):
#countofrooms: num rooms
#listRooms rooms to look for alibabba
possiblePlaces = []
#initialize rooms
for i in range(countOfRooms):
possiblePlaces.append(True)
for i in range(len(strategy)):
roomToCheck = strategy[i]
#Room is marked as unavailable
possiblePlaces[roomToCheck] = False
#Next day calculatins
nextDayPlaces = []
for j in range(countOfRooms):
nextDayPla"See full answer
"// Helper function to calculate the Euclidean distance between two points
function distance(p1, p2) {
return Math.sqrt(Math.pow(p1[0] - p2[0], 2) + Math.pow(p1[1] - p2[1], 2));
}
// A helper function to find the closest pair in a given set of points within the strip
function closestPairInStrip(strip, d) {
let minDist = d; // Start with the current minimum distance
strip.sort((a, b) => a[1] - b[1]); // Sort the strip by y-coordinate
for (let i = 0; i < strip.length; i++) {
"
Vishnu V. - "// Helper function to calculate the Euclidean distance between two points
function distance(p1, p2) {
return Math.sqrt(Math.pow(p1[0] - p2[0], 2) + Math.pow(p1[1] - p2[1], 2));
}
// A helper function to find the closest pair in a given set of points within the strip
function closestPairInStrip(strip, d) {
let minDist = d; // Start with the current minimum distance
strip.sort((a, b) => a[1] - b[1]); // Sort the strip by y-coordinate
for (let i = 0; i < strip.length; i++) {
"See full answer
"Determine the requirements
Perform basic checks on the frontend before submitting to the server
Length
Check for invalid or required characters
Client-side validation messaging
Perform more advanced checks on the server if required
Does the password include the user's name, etc
Handle server-side validation messaging"
Casey C. - "Determine the requirements
Perform basic checks on the frontend before submitting to the server
Length
Check for invalid or required characters
Client-side validation messaging
Perform more advanced checks on the server if required
Does the password include the user's name, etc
Handle server-side validation messaging"See full answer
"from typing import List
def traprainwater(height: List[int]) -> int:
if not height:
return 0
l, r = 0, len(height) - 1
leftMax, rightMax = height[l], height[r]
res = 0
while l < r:
if leftMax < rightMax:
l += 1
leftMax = max(leftMax, height[l])
res += leftMax - height[l]
else:
r -= 1
rightMax = max(rightMax, height[r])
"
Anonymous Roadrunner - "from typing import List
def traprainwater(height: List[int]) -> int:
if not height:
return 0
l, r = 0, len(height) - 1
leftMax, rightMax = height[l], height[r]
res = 0
while l < r:
if leftMax < rightMax:
l += 1
leftMax = max(leftMax, height[l])
res += leftMax - height[l]
else:
r -= 1
rightMax = max(rightMax, height[r])
"See full answer