注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
分享8月亚麻oa 准备材料,考到的题目全在里面。 9月可能出了新题了,大家有备无患。路过求加米 谢谢
parking lot
You are given an List of positions of cars as to where they are parked. You are also given an integer K.
The cars needs to be covered with a roof. You have to find the minimum length of roof that takes to cover K cars.
Input : 12,6,5,2 K = 3
Explanation : There are two possible roofs that can cover K cars. One that covers the car in 2,5,6 parking spots and
another roof which covers 5,6,12 parking spots. The length of these two roofs are 5 and 8 respectively. Return 5
since that's the roof with minimum length that covers K cars.
Output : 5
a=[3,5,7,8,9,53,67,124]
k=6
if not partking_spots or k==0:
return 0
if k > len(parking_spots):
return float('inf')
a.sort()
x=0
minLength=float('inf')
for idx,num in enumerate(a):
if idx-x+1==k:
minLength=min(minLength,num-a[x]+1)
x+=1
print(minLength)
Decode the input string into original string.
You are given an encoded string and number of rows, Convert it to original string
Input: mnesi___ya__k____mime N = 3
Output : my name is mike
Explanation : Read the matrix in a diagonal way starting from [0][0] index until the end of row and start from the top
again to decode it. _ are treated as space.
m n e s i _ _
_ y a _ _ k _
_ _ _ m i m e
def build_matrix(input_string, mat_size):
matrix = []
num_chars_per_row = len(input_string) // mat_size
for i in range(0, len(input_string), num_chars_per_row):
row = list(input_string[i:i + num_chars_per_row])
matrix.append(row)
return matrix
# Question: Are the leading spaces in the output to be removed?
def decode_input_string(input_string, mat_size):
# Input Validations...
if not input_string: return ""
malections.Counter(a)
if abs(freq["("]-freq[")"])+abs(freq["["]-freq["]"])>freq["?"]:
return None
countRound,countSquare,countQuestion=0,0,0
for c in a:
if c=="(":
countRound+=1
elif c==")":
countRound-=1
elif c=="[":
countSquare+=1
elif c=="]":
countSquare-=1
elif c=="?":
countQuestion+=1
if abs(countRound) + abs(countSquare) <= countQuestion:
# left is correct
res+=1
return res-1
leftsum bigger than rightsum
compress priority
put in hashmap, then sort into a list.
Secret array
need to +1; need to return 0
Demolition Robot
Amazon Fresh Deliveries
reorder data in log files L937
Clear path in matrix L1901
|