This is a good implementation of the recursive approach. Which is the first thing that comes to mind when interviewing. The problem with this solution, is time complexity which is O(2^n) where n is the length of s. A better approach is to use Dynamic programming. Then the time and space complexity become O(p1p2) where p1 is the length of part1 and p2 the length of p2.
That is an interesting question.
I could have converted them first to numbers but it is not needed.
JavaScript string comparison is alphabetical. Alphabeticaly '11' is less than '12'. That is how it works.
This is a good implementation of the recursive approach. Which is the first thing that comes to mind when interviewing. The problem with this solution, is time complexity which is O(2^n) where n is the length of s. A better approach is to use Dynamic programming. Then the time and space complexity become O(p1p2) where p1 is the length of part1 and p2 the length of p2.
Make some simple expamples like [4,2,1,3] test it with 'R' an with 'L', try to see if you notice a pattern
That is an interesting question.
I could have converted them first to numbers but it is not needed.
JavaScript string comparison is alphabetical. Alphabeticaly '11' is less than '12'. That is how it works.
!
Here is some advice how to approach this. Solve some examples on paper first. Notice what happens. Then coding the solution is easy.
!
!
This comment is hidden because it contains spoiler information about the solution
!
Nice kata! I saw some really clever solutions and some good practices. Thanks.
!
!
!
Interesting kata but unfortunately very bad description.
!
Loading more items...