Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
GITHUB - "The Highest Building" solution in Uncategorized category for The Highest Building by jsg-inet
def highest_building(buildings):
# First we "level" the city, removing all "0" rows
city_leveled=[x for x in buildings if 1 in x]
# Finally we give the index of the "1" (only one is present) adding 1 (number of bouildings starts in 1)
# and the number of rows of the leveled city (height of the highest building)
return [city_leveled[0].index(1)+1 , len(city_leveled)]
if __name__ == '__main__':
print("Example:")
print(highest_building([
[0, 0, 1, 0],
[1, 0, 1, 0],
[1, 1, 1, 0],
[1, 1, 1, 1]
]))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert highest_building([
[0, 0, 1, 0],
[1, 0, 1, 0],
[1, 1, 1, 0],
[1, 1, 1, 1]
]) == [3, 4], "Common"
assert highest_building([
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 1]
]) == [4, 1], "Cabin in the wood"
assert highest_building([
[1, 0, 0, 0, 0],
[1, 1, 0, 0, 0],
[1, 1, 1, 0, 0],
[1, 1, 1, 1, 0],
[1, 1, 1, 1, 1]
]) == [1, 5], "Triangle"
assert highest_building([
[0, 0, 0, 1, 0, 0, 0],
[0, 0, 1, 1, 1, 0, 0],
[0, 1, 1, 1, 1, 1, 0],
[1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1]
]) == [4, 6], "Pyramid"
print("Coding complete? Click 'Check' to earn cool rewards!")
June 24, 2021
Comments: