get help in general - we have more specialized help rooms here: https://gitter.im/FreeCodeCamp/home

Hello, I'm having trouble finding an efficient way of doing "permutation step" coderbyte challenge.

I already found a "simple" solution, but it's too slow with big numbers

could anyone give me some insight on how to approach the problem in a better way?

Can someone help me with this, I have it on floobits where we can code together live. /* 1. Create a Bank constructor function

```
2. The constructor function should have a balance property equal to 100
3. Add a credit function to Banks prototype that will add to balance
4. Add a debit function to the Banks prototype that will subtract from the balance
5. Create an instance of the bank
6. Create a loop that will run three times and prompt the user for a number input
7. Parse the values into numbers
8. Call the bank.credit(num) function and add that amount to your balance
9. Create a new loop that will run twice
10. Inside this loop prompt for a number and parse the number
11. Run these two numbers with the bank.debit(num) to subtract from the balance
12. Finally, log the ending balance after the three credits and two debits.
For instance, if you start with 100, credit 10 three times, we get 130, then debit 10 twice, we get 110.*/
```

@JesseJHernandez has anyone helped you yet?

No

Not yet

ok

so what code have you written so far?

@cristian-berrios I just completed that but I'm not sure if my solution is better than yours. What's your solution?

I came with a better algorithm, just need to code it

previous was

split num into array, sort it and parse it so you can get the max number possible

then iterating from original to max and checking each one using the "string reordering" function from previous challeng

challenge

until you found a number containing all the digits

but it took about a minute with 978654321

so I came with a better idea

how is the new algorithm?

1st split the number into an array, so 11121 becomes [1,1,1,2,1]

then, make a loop where you progressively test sub-arrays from the end (less significative digits)

so, at 1st you get [2,1]

then, sort that array, transform it into a number and see if "21" is biger than "21"

if not, then do the same with 3 digits

now [2,1,1] is bigger than [1,2,1]

so you get 1st digit "2" and sort the rest from smallest to biggest

and you get [2,1,1] (same in this case)

and from that you return the final number

[1,1] + [2,1,1]

I did something similar

only I simply use a for loop starting from the end of the array and switch the first couple where num[i] - num[i-1] >0, then sort from i to the end

but that doesn't cover all the cases

like... [2,3,1,1,1,8]

you would be swapping 2 with 3

hmm going from back I think it's ok

well, I'll try to do it now, link your answer to compare :D

Maybe I didn't explain my code well, but it did pass all test cases. The link is this:

http://coderbyte.com/CodingArea/Results.php?ct=Permutation%20Step&user=surikmeetr&lan=JavaScript

http://coderbyte.com/CodingArea/Results.php?ct=Permutation%20Step&user=surikmeetr&lan=JavaScript

It took me two tries to get it right, don't mind the time written there

I think yours is better

anyone know how to get more time on codeschool to complete challenges?

sure

create another account with another email :D

also, since codeSchool just got bought, they are giving 72 hours to new accounts

oh nice

just noticed

has anyone used pluralsight?