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.
Sequence Equation
Sequence Equation
Sort by
recency
|
1549 Discussions
|
Please Login in order to post a comment
My solution
def permutationEquation(p): return [p.index(p.index(x) + 1) + 1 for x in sorted(p)]
I am just learning Python, so the syntax where I use one line with the for cycle at the end is new to me. Originally I wrote:
def permutationEquation(p): answer = []
I totally agree! When I had just read the problem, I thought that I probably could get it in one line of code. Focusing on reducing equipment failure as a mindset, I broke the entire problem into just a few steps and was able to get a solution that only took one line of code!
**Mine Python Solution **
C++ solution