Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
the glass is twice as big as it needs to be
:]
Don't even try to simulate everything that happens. That's nice to see patterns and validate your solution against smaller inputs ( because it means you can generate tests yourself ), but it's never going to work for bigger inputs.
There's a reason this kata has a
performance
tag and a specified upper bound.O(n²)
won't cut it; you'll needO(n)
or very close to it.If it makes you feel better, my first solutions ( yes, plural ) turned out not to be able to handle a million ants either ( though I could handle a hundred thousand; I skipped simulating entirely ).
Difficult to decide whether you'd use the ternary for the smallest code or use an if statement to make it more readable for someone else. I guess you'd go with the ternary because a dev should be able to recognise it.
👍
Yes, you can use z to hold the resulting array, you can also delete it and write your code inside the function too if you want.