You are going to build a stone wall. The wall should be straight and N meters long, and its thickness should be constant; however, it should have different heights in different places. The height of the wall is specified by an array H of N positive integers. H[I] is the height of the wall from I to I+1 meters to the right of its left end. In particular, H[0] is the height of the wall's left end and H[N−1] is the height of the wall's right end.
The wall should be built of cuboid stone blocks (that is, all sides of such blocks are rectangular). Your task is to compute the minimum number of blocks needed to build the wall.
Write a function:
def solution(H)
that, given an array H of N positive integers specifying the height of the wall, returns the minimum number of blocks needed to build it.
For example, given array H containing N = 9 integers:
H[0] = 8 H[1] = 8 H[2] = 5 H[3] = 7 H[4] = 9 H[5] = 8 H[6] = 7 H[7] = 4 H[8] = 8the function should return 7. The figure shows one possible arrangement of seven blocks.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- each element of array H is an integer within the range [1..1,000,000,000].
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque()
count = 0
for hei in H:
if queue:
if hei < queue[0]:
while queue:
queue
else:
stack.append(hei)
if stack:
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
while queue:
queue
else:
stack.append(hei)
if queue:
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
while queue:
queue.poplef
else:
queue.append(hei)
if queue:
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
while queue:
before_num = queue.popleft()
else:
queue.append(hei)
if queue:
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
while queue:
before_num = queue.pop()
else:
queue.append(hei)
if queue:
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
while queue:
before_num = queue.popleft()
else:
queue.append(hei)
if queue:
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
while queue:
before_num = queue.popleft()
else:
queue.append(hei)
if queue:
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
while queue:
before_num = queue.popleft()
else:
queue.append(hei)
if queue:
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
if before_num = 0
while queue:
before_num = queue.popleft()
else:
queue.append(hei)
if queue:
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
before_num = 0
while queue:
before_num
before_num = queue.popleft()
else:
queue.append(hei)
if queue:
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
before_num = 0
while queue:
before_num
before_num = queue.popleft()
before_num.appedn
else:
queue.append(hei)
if queue:
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
before_num = 0
while queue:
before_num
before_num = queue.popleft()
queue.append()
else:
queue.append(hei)
if queue:
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
before_num = 0
while queue:
before_num
before_num = queue.popleft()
queue.append(hei)
else:
queue.append(hei)
if queue:
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
before_num = 0
while queue:
queue[0] > before_num
before_num = queue.popleft()
queue.append(hei)
else:
queue.append(hei)
if queue:
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
queue.append(hei)
else:
queue.append(hei)
if queue:
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
queue.append(hei)
else:
queue.append(hei)
if queue:
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
queue.append(hei)
else:
queue.append(hei)
if queue:
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
queue.append(hei)
else:
queue.append(hei)
before_num = 0
while queue:
if queue[0] > be
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
queue.append(hei)
else:
queue.append(hei)
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
queue.append(hei)
else:
queue.append(hei)
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(count)
Invalid result type, int expected, <class 'NoneType'> found.stdout:
6
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
queue.append(hei)
else:
queue.append(hei)
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print(hei)
print(queue)
if queue:
if hei < queue[0]:
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
queue.append(hei)
else:
queue.append(hei)
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(count)
Invalid result type, int expected, <class 'NoneType'> found.stdout:
8 deque([]) 8 deque([8]) 5 deque([8, 8]) 7 deque([5]) 9 deque([5, 7]) 8 deque([5, 7, 9]) 7 deque([5, 7, 9, 8]) 4 deque([5, 7, 9, 8, 7]) 8 deque([4]) 6
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print(hei)
print(queue)
p[]
if queue:
if hei < queue[0]:
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
queue.append(hei)
else:
queue.append(hei)
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print(hei)
print(queue)
print(count)
if queue:
if hei < queue[0]:
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
queue.append(hei)
else:
queue.append(hei)
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(count)
Invalid result type, int expected, <class 'NoneType'> found.stdout:
8 deque([]) 0 8 deque([8]) 0 5 deque([8, 8]) 0 7 deque([5]) 1 9 deque([5, 7]) 1 8 deque([5, 7, 9]) 1 7 deque([5, 7, 9, 8]) 1 4 deque([5, 7, 9, 8, 7]) 1 8 deque([4]) 4 6
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print(hei)
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
queue.append(hei)
else:
queue.append(hei)
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
queue.append(hei)
else:
queue.append(hei)
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(count)
Invalid result type, int expected, <class 'NoneType'> found.stdout:
height ::: 8 deque([]) count ::: 0 height ::: 8 deque([8]) count ::: 0 height ::: 5 deque([8, 8]) count ::: 0 height ::: 7 deque([5]) count ::: 1 height ::: 9 deque([5, 7]) count ::: 1 height ::: 8 deque([5, 7, 9]) count ::: 1 height ::: 7 deque([5, 7, 9, 8]) count ::: 1 height ::: 4 deque([5, 7, 9, 8, 7]) count ::: 1 height ::: 8 deque([4]) count ::: 4 6
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
queue.append(hei)
else:
queue.append(hei)
before_num = 0
while queue:
print
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
queue.append(hei)
else:
queue.append(hei)
print("leave count ")
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(count)
Invalid result type, int expected, <class 'NoneType'> found.stdout:
height ::: 8 deque([]) count ::: 0 height ::: 8 deque([8]) count ::: 0 height ::: 5 deque([8, 8]) count ::: 0 height ::: 7 deque([5]) count ::: 1 height ::: 9 deque([5, 7]) count ::: 1 height ::: 8 deque([5, 7, 9]) count ::: 1 height ::: 7 deque([5, 7, 9, 8]) count ::: 1 height ::: 4 deque([5, 7, 9, 8, 7]) count ::: 1 height ::: 8 deque([4]) count ::: 4 leave count deque([4, 8]) deque([8]) 6
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
queue.append(hei)
else:
queue.append(hei)
print("leave count ")
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print()
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
queue.append(hei)
else:
queue.append(hei)
print("leave count ")
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
Invalid result type, int expected, <class 'NoneType'> found.stdout:
height ::: 8 deque([]) count ::: 0 height ::: 8 deque([8]) count ::: 0 height ::: 5 deque([8, 8]) count ::: 0 height ::: 7 deque([5]) count ::: 1 height ::: 9 deque([5, 7]) count ::: 1 height ::: 8 deque([5, 7, 9]) count ::: 1 height ::: 7 deque([5, 7, 9, 8]) count ::: 1 height ::: 4 deque([5, 7, 9, 8, 7]) count ::: 1 height ::: 8 deque([4]) count ::: 4 leave count deque([4, 8]) deque([8]) deque([]) 6
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
while queue:
if queue[0] > before_num:
tempcount += 1
before_num = queue.popleft()
queue.append(hei)
else:
queue.append(hei)
print("leave count ")
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
while queue:
if queue[0] > before_num:
temp_count += 1
before_num = queue.popleft()
queue.append(hei)
else:
queue.append(hei)
print("leave count ")
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
while queue:
if queue[0] > before_num:
temp_count += 1
before_num = queue.popleft()
count += temp_count
queue.append(hei)
else:
queue.append(hei)
print("leave count ")
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
while queue:
if queue[0] > before_num:
temp_count += 1
before_num = queue.popleft()
print("temp_count ::: " + str(temp_count))
count += temp_count
queue.append(hei)
else:
queue.append(hei)
print("leave count ")
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
while queue:
if queue[0] > before_num:
temp_count += 1
before_num = queue.popleft()
print("temp_count ::: " + str(temp_count))
count += temp_count
queue.append(hei)
else:
queue.append(hei)
print("leave count ")
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
Invalid result type, int expected, <class 'NoneType'> found.stdout:
height ::: 8 deque([]) count ::: 0 height ::: 8 deque([8]) count ::: 0 height ::: 5 deque([8, 8]) count ::: 0 temp_count ::: 1 height ::: 7 deque([5]) count ::: 1 height ::: 9 deque([5, 7]) count ::: 1 height ::: 8 deque([5, 7, 9]) count ::: 1 height ::: 7 deque([5, 7, 9, 8]) count ::: 1 height ::: 4 deque([5, 7, 9, 8, 7]) count ::: 1 temp_count ::: 3 height ::: 8 deque([4]) count ::: 4 leave count deque([4, 8]) deque([8]) deque([]) 6
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
while queue:
if queue[0] > before_num:
temp_count += 1
before_num = queue.popleft()
print("temp_count ::: " + str(temp_count))
count += temp_count
queue.append(hei)
else:
queue.append(hei)
print("leave count ")
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
before_num = queue.popleft()
print("temp_count ::: " + str(temp_count))
count += temp_count
queue.append(hei)
else:
queue.append(hei)
print("leave count ")
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif
before_num = queue.popleft()
print("temp_count ::: " + str(temp_count))
count += temp_count
queue.append(hei)
else:
queue.append(hei)
print("leave count ")
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash == 0:
before_num = queue.popleft()
print("temp_count ::: " + str(temp_count))
count += temp_count
queue.append(hei)
else:
queue.append(hei)
print("leave count ")
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash == 0:
temp_count += 1
temp_hash[] = 1
before_num = queue.popleft()
print("temp_count ::: " + str(temp_count))
count += temp_count
queue.append(hei)
else:
queue.append(hei)
print("leave count ")
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash == 0:
temp_count += 1
before_num = queue.popleft()
print("temp_count ::: " + str(temp_count))
count += temp_count
queue.append(hei)
else:
queue.append(hei)
print("leave count ")
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash == 0:
temp_count += 1
before_num = queue.popleft()
print("temp_count ::: " + str(temp_count))
count += temp_count
queue.append(hei)
else:
queue.append(hei)
print("leave count ")
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash == 0:
temp_count += 1
before_num = queue.popleft()
before_
print("temp_count ::: " + str(temp_count))
count += temp_count
queue.append(hei)
else:
queue.append(hei)
print("leave count ")
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash == 0:
temp_count += 1
before_num = queue.popleft()
temp_hash[]
print("temp_count ::: " + str(temp_count))
count += temp_count
queue.append(hei)
else:
queue.append(hei)
print("leave count ")
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash == 0:
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
print("temp_count ::: " + str(temp_count))
count += temp_count
queue.append(hei)
else:
queue.append(hei)
print("leave count ")
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
Invalid result type, int expected, <class 'NoneType'> found.stdout:
height ::: 8 deque([]) count ::: 0 height ::: 8 deque([8]) count ::: 0 height ::: 5 deque([8, 8]) count ::: 0 temp_count ::: 1 height ::: 7 deque([5]) count ::: 1 height ::: 9 deque([5, 7]) count ::: 1 height ::: 8 deque([5, 7, 9]) count ::: 1 height ::: 7 deque([5, 7, 9, 8]) count ::: 1 height ::: 4 deque([5, 7, 9, 8, 7]) count ::: 1 temp_count ::: 3 height ::: 8 deque([4]) count ::: 4 leave count deque([4, 8]) deque([8]) deque([]) 6
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash == 0:
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
print("temp_count ::: " + str(temp_count))
count += temp_count
queue.append(hei)
else:
queue.append(hei)
print("leave count ")
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
Invalid result type, int expected, <class 'NoneType'> found.stdout:
height ::: 8 deque([]) count ::: 0 height ::: 8 deque([8]) count ::: 0 height ::: 5 deque([8, 8]) count ::: 0 temp_count ::: 1 height ::: 7 deque([5]) count ::: 1 height ::: 9 deque([5, 7]) count ::: 1 height ::: 8 deque([5, 7, 9]) count ::: 1 height ::: 7 deque([5, 7, 9, 8]) count ::: 1 height ::: 4 deque([5, 7, 9, 8, 7]) count ::: 1 temp_count ::: 3 height ::: 8 deque([4]) count ::: 4 leave count deque([4, 8]) deque([8]) deque([]) 6
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash == 0:
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
print("temp_count ::: " + str(temp_count))
count += temp_count
queue.append(hei)
else:
queue.append(hei)
print("leave count ")
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash == 0:
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
print(temp_hash)
print("temp_count ::: " + str(temp_count))
count += temp_count
queue.append(hei)
else:
queue.append(hei)
print("leave count ")
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash == 0:
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
print("temp_hash ::: " + str(temp_hash))
print("temp_count ::: " + str(temp_count))
count += temp_count
queue.append(hei)
else:
queue.append(hei)
print("leave count ")
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
Invalid result type, int expected, <class 'NoneType'> found.stdout:
height ::: 8 deque([]) count ::: 0 height ::: 8 deque([8]) count ::: 0 height ::: 5 deque([8, 8]) count ::: 0 temp_hash ::: defaultdict(<class 'int'>, {8: 1}) temp_count ::: 1 height ::: 7 deque([5]) count ::: 1 height ::: 9 deque([5, 7]) count ::: 1 height ::: 8 deque([5, 7, 9]) count ::: 1 height ::: 7 deque([5, 7, 9, 8]) count ::: 1 height ::: 4 deque([5, 7, 9, 8, 7]) count ::: 1 temp_hash ::: defaultdict(<class 'int'>, {5: 1, 7: 1, 9: 1, 8: 1}) temp_count ::: 3 height ::: 8 deque([4]) count ::: 4 leave count deque([4, 8]) deque([8]) deque([]) 6
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash == 0:
print
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
print("temp_hash ::: " + str(temp_hash))
print("temp_count ::: " + str(temp_count))
count += temp_count
queue.append(hei)
else:
queue.append(hei)
print("leave count ")
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash == 0:
print("tmep+_before:::" + str(before_num))
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
print("temp_hash ::: " + str(temp_hash))
print("temp_count ::: " + str(temp_count))
count += temp_count
queue.append(hei)
else:
queue.append(hei)
print("leave count ")
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash[q] == 0:
print("tmep+_before:::" + str(before_num))
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
print("temp_hash ::: " + str(temp_hash))
print("temp_count ::: " + str(temp_count))
count += temp_count
queue.append(hei)
else:
queue.append(hei)
print("leave count ")
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0:
print("tmep+_before:::" + str(before_num))
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
print("temp_hash ::: " + str(temp_hash))
print("temp_count ::: " + str(temp_count))
count += temp_count
queue.append(hei)
else:
queue.append(hei)
print("leave count ")
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
Invalid result type, int expected, <class 'NoneType'> found.stdout:
height ::: 8 deque([]) count ::: 0 height ::: 8 deque([8]) count ::: 0 height ::: 5 deque([8, 8]) count ::: 0 temp_hash ::: defaultdict(<class 'int'>, {8: 1}) temp_count ::: 1 height ::: 7 deque([5]) count ::: 1 height ::: 9 deque([5, 7]) count ::: 1 height ::: 8 deque([5, 7, 9]) count ::: 1 height ::: 7 deque([5, 7, 9, 8]) count ::: 1 height ::: 4 deque([5, 7, 9, 8, 7]) count ::: 1 tmep+_before:::9 temp_hash ::: defaultdict(<class 'int'>, {5: 1, 7: 1, 9: 1, 8: 1}) temp_count ::: 4 height ::: 8 deque([4]) count ::: 5 leave count deque([4, 8]) deque([8]) deque([]) 7
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0:
print("tmep+_before:::" + str(before_num))
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
print("temp_hash ::: " + str(temp_hash))
print("temp_count ::: " + str(temp_count))
count += temp_count
queue.append(hei)
else:
queue.append(hei)
before_num = 0
while queue:
print(queue)
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0:
print("tmep+_before:::" + str(before_num))
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
print("temp_hash ::: " + str(temp_hash))
print("temp_count ::: " + str(temp_count))
count += temp_count
queue.append(hei)
else:
queue.append(hei)
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0:
print("tmep+_before:::" + str(before_num))
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
print("temp_hash ::: " + str(temp_hash))
print("temp_count ::: " + str(temp_count))
count += temp_count
queue.append(hei)
else:
queue.append(hei)
temp_hash = collections.defaultdict(int)
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
before_num = queue.popleft()
print(queue)
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0:
print("tmep+_before:::" + str(before_num))
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
print("temp_hash ::: " + str(temp_hash))
print("temp_count ::: " + str(temp_count))
count += temp_count
queue.append(hei)
else:
queue.append(hei)
temp_hash = collections.defaultdict(int)
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0 :
temp_count += 1
before_num = queue.popleft()
print(queue)
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0:
print("tmep+_before:::" + str(before_num))
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
print("temp_hash ::: " + str(temp_hash))
print("temp_count ::: " + str(temp_count))
count += temp_count
queue.append(hei)
else:
queue.append(hei)
temp_hash = collections.defaultdict(int)
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0 :
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
print(queue)
print(count)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
print("height ::: " + str(hei))
print(queue)
print("count ::: " + str(count))
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0:
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
count += temp_count
queue.append(hei)
else:
queue.append(hei)
temp_hash = collections.defaultdict(int)
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0 :
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
return count
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0:
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
count += temp_count
queue.append(hei)
else:
queue.append(hei)
temp_hash = collections.defaultdict(int)
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0 :
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
return count
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0:
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
count += temp_count
queue.append(hei)
else:
queue.append(hei)
temp_hash = collections.defaultdict(int)
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0 :
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
return count
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0:
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
count += temp_count
queue.append(hei)
else:
queue.append(hei)
temp_hash = collections.defaultdict(int)
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0 :
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
return count
[5, 6, 9, 8, 8, 5, 7]
Traceback (most recent call last): File "exec.py", line 129, in <module> main() File "exec.py", line 91, in main result = solution( H ) File "/tmp/solution.py", line 34, in solution temp_count += 1 UnboundLocalError: local variable 'temp_count' referenced before assignment
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0:
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
count += temp_count
queue.append(hei)
else:
queue.append(hei)
temp_hash = collections.defaultdict(int)
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0 :
before_num = queue.popleft()
temp_hash[before_num] = 1
return count
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0:
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
count += temp_count
queue.append(hei)
else:
queue.append(hei)
temp_hash = collections.defaultdict(int)
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0 :
count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
return count
[5, 6, 9, 8, 8, 5, 7]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0:
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
count += temp_count
queue.append(hei)
else:
queue.append(hei)
temp_hash = collections.defaultdict(int)
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0 :
count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
return count
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0:
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
count += temp_count
queue.append(hei)
else:
queue.append(hei)
temp_hash = collections.defaultdict(int)
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0 :
count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
return count
[5, 6, 9, 8, 8, 5, 7]
[1]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0:
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
count += temp_count
queue.append(hei)
else:
queue.append(hei)
temp_hash = collections.defaultdict(int)
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0 :
count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
return count
[5, 6, 9, 8, 8, 5, 7]
[1]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
import collections
def solution(H):
queue = collections.deque([])
count = 0
for hei in H:
if queue:
if hei < queue[0]:
before_num = 0
temp_count = 0
temp_hash = collections.defaultdict(int)
while queue:
if queue[0] > before_num:
temp_count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0:
temp_count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
count += temp_count
queue.append(hei)
else:
queue.append(hei)
temp_hash = collections.defaultdict(int)
before_num = 0
while queue:
if queue[0] > before_num:
count += 1
elif queue[0] < before_num and temp_hash[queue[0]] == 0 :
count += 1
before_num = queue.popleft()
temp_hash[before_num] = 1
return count
The following issues have been detected: wrong answers.