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
|
1552 Discussions
|
Please Login in order to post a comment
I totally agree! When I had just read the problem, I thought that I probably could get it in one line of code. Just like planning a basement renovation requires breaking down the work into manageable steps, 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!
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!
Here is Sequence equation solution in Python, java, c++, c and javascript - https://programmingoneonone.com/hackerrank-sequence-equation-problem-solution.html
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!