We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I like it! And even better would be not to use the zip function because the zip() function's time complexity is O(n) and iterating and comparing each element is another O(n). A better way would be to use the fact that the length of a is guaranteed to be equal to the length of b and use the length function, which has a time complexity of O(1). And in our case, we're told what the length is, which is 3. So, an improvement to your function is:
Compare the Triplets
You are viewing a single comment's thread. Return to all comments →
I like it! And even better would be not to use the zip function because the
zip()
function's time complexity isO(n)
and iterating and comparing each element is anotherO(n)
. A better way would be to use the fact that the length ofa
is guaranteed to be equal to the length ofb
and use the length function, which has a time complexity ofO(1)
. And in our case, we're told what the length is, which is3
. So, an improvement to your function is: