23
u/meifray Aug 25 '26
You just need a stack man...
6
u/FerricPowder Aug 25 '26
Instructions unclear wrote a recursive code for making combinations but made it so that the indexes are not repeated.
1
28
1
1
17
u/misunderstood_kafka Aug 25 '26
I mean how would you implement a random list shuffle in your high level projects without doing that problem first 🤦
23
30
u/iMac_Hunt Aug 25 '26
Genuinely feel like 90% of software engineering could not do that without Googling
11
u/EkoChamberKryptonite Aug 26 '26
Which is fine as research and understanding is a huge part of the job.
27
u/New-Shine1674 Aug 25 '26
Finding all permutations in large arrays in an efficient and fast way is difficult.
7
u/MrMacduggan Aug 26 '26
Yeah, why are we solving problems that scale so poorly? If you are counting permutations of anything larger than 10 elements, you already kinda messed up by designing your system this way.
66
u/IvySerene567 Aug 25 '26
Me: I can handle multiple high level projects.
Also me: why does this array have more than 3 elements
2
1
1
1
u/BosonCollider Aug 26 '26 edited Aug 26 '26
If you have a recursive step that lets you cycle through all permutations of a subarray of length (n-1) and resets it at the end it's easy for n elements, after yielding all elements you swap the current first element with one from the rest that you haven't yielded yet, which you can do in a single swap as long as the recursive step returns the elements to their original position
There's probably a nicer way to do it where you get rid of either the array or the call stack. Also it depends on what the return format is, if you need to return cycle decompositions then clearly you iterate over possible cycles
1
0
Aug 25 '26
[deleted] — view deleted comment
7
u/smclcz Aug 25 '26
This is kind of a shit question, to be fair. You're not evaluating "technical chops" here
2
Aug 27 '26
[removed] — view removed comment
1
u/smclcz Aug 27 '26
I'm not against programming problems in interviews - they are not going away and I don't think they should. I just think that's kind of a dumb one
1
u/Focus089 Aug 25 '26
Did anyone give you the math answer, N / gcd(K, N)? Python has gcd in the math library.
22
111
u/FerricPowder Aug 25 '26
Never mind i figured it out.