Untitled
unknown
python
2 years ago
1.4 kB
10
Indexable
def tests():
assert max_intersections(['U 1', 'U 2', 'U 3', 'D 4', 'D 5'], "y") == 5
assert max_intersections(['U 1', 'U 2', 'U 2', 'D 4', 'D 5'], "y") == 5
assert max_intersections(['U 1', 'U 10', 'D 3'], "y") + max_intersections(['L 2'], "y") == 3
assert max_intersections(["U 1", "U 2", "U 2", "D 4"], "y") == 4
assert max_intersections(["D 1", "U 2"], "y") == 1
assert max_intersections(["L 2", "L 10"], "x") == 2
assert max_intersections(["U 1", "U 1", "D 2", "D 2"], "y") == 4
assert max_intersections(["U 1", "U 1", "D 2", "D 2", "D 3"], "y") == 5
assert max_intersections(['U 2', 'U 2', 'D 2', 'D 2'], "y") == 4
assert max_intersections(['U 2', 'U 2', 'D 1', 'D 1'], "y") == 2
assert max_intersections(['U 2', 'U 3', 'D 4', 'U 5', 'D 6'], "y") == 4
def max_intersections(princes, direction):
if direction == "x":
more_sym = "R"
less_sym = "L"
else:
more_sym = "U"
less_sym = "D"
more = [int(pr.split()[1]) for pr in princes if pr.startswith(more_sym)]
less = [int(pr.split()[1]) for pr in princes if pr.startswith(less_sym)]
result = max(len(less), len(more))
if not (more and less):
return result
min_more = min(more)
more_result = sum(1 for l in less if l >= min_more) + 1
max_less = max(less)
less_result = sum(1 for m in more if m <= max_less) + 1
return max(more_result, less_result, result)
tests()Editor is loading...
Leave a Comment