This comment is hidden because it contains spoiler information about the solution
.
If n is the number of pieces, yes as i was talking about like two nested for loops, it is either O(n) or O(n * m) where n, m is height and length.
I also don't believe any solutions are O(n^2) if n is the number of pieces. By doing a simple nested loop with for p in pieces: twice, it times out.
for p in pieces:
Your solution is much easier to understand! Months later, this is true for me, even though I wrote my code...
first things first: what is n exactly?
n
@tony:
here, n being the number of pieces, the best solution is O(n) (for the precise reasons Ryanman is explaning)
I think O(n^2) is the lowest possible time as you need to have a nested loop. Take your solution for example, it has a nested loop, so its O(n^2).
Loading collection data...
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
.
If n is the number of pieces, yes as i was talking about like two nested for loops, it is either O(n) or O(n * m) where n, m is height and length.
I also don't believe any solutions are O(n^2) if n is the number of pieces. By doing a simple nested loop with
for p in pieces:
twice, it times out.Your solution is much easier to understand! Months later, this is true for me, even though I wrote my code...
first things first: what is
n
exactly?@tony:
here, n being the number of pieces, the best solution is O(n) (for the precise reasons Ryanman is explaning)
I think O(n^2) is the lowest possible time as you need to have a nested loop. Take your solution for example, it has a nested loop, so its O(n^2).