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.
I am commenting here, since it is the top solution. Is it habitual on Codewars not to take care of failures of system calls? No one seems to do it however, for example here, the program will collapse if malloc() fails and returns NULL.
I do not think efficiency matters a lot here since we are dealing with an input of constant size (the chessboard – always 64 tiles).
The possibility of a jagged matrix (i. e. lines of variable length) defeat the concept of "instructions scattered over a ‹two-dimensional plane›". It would only make sense to receive the input as a 2D matrix (i. e. a list of lists of fixed length).
I used BFS too and did not have an issue with time. After all, BFS has the best possible time complexity for a graph searching algorithm.
There may be a little bug that causes your solution to loop endlessly.
If you are a beginner, please, be informed, that while these one-liners may look "cool", this is not what you want to do.
What is the point of the format of the test cases? Why have the lines be joined with '\n' when we are going to parse them into a matrix anyway?
What was I thinking? Why store it in a variable when you can just use ord('a')...
Declaring what the type of 'maze' is would be nice. Also, I see most (if not all) solutions split the string into lines by '\n'. A list of lists (or at least list of strings) is easier to work with and makes much more sense in a task like this.
The idea is that no number from the interval (n/2, n) will ever be a divisor of n.
You are almost correct, however, we need to be careful about how we simplify the equations. The time complexity of making a single slice is (omikron) O(n). Making two of them, theoretically has a time complexity of O(n + n = 2n). Note that we are adding, not multiplying. Since 2 is a constant, we can omit counting it. (In other words, the functions n and 2n grow at the same rate.) Just making the slices has therefore a time complexity of O(n).
This happens for every element, so we then multiply by n and get O(n²).
This comment is hidden because it contains spoiler information about the solution
Yes. The "else: pass" in your code can be omitted without any issues.
I'm not sure if I understood you correctly, but this is, in fact, O(n^2) too.
While one-liners look smart and cool, this is not really good practice. For every element of the list we make a slice (so in worst case, we go over all of its elements again) and then call the count method on the slice (by which we go over all of the elements of the slice).
In the end, what could be done with just one iteration over the list, is done with numerous redundant iterations.
This comment is hidden because it contains spoiler information about the solution
Loading more items...