All Questions
14 questions
2
votes
1
answer
256
views
Time and Space Complexity of Leetcode Problem #31. Next Permutation
The question is as follows: Given a collection of distinct integers, return all possible permutations. Example:
...
7
votes
2
answers
6k
views
Permutations with replacement in Python
Many a times, I've had the need to use a permutations with replacement function.
So, I've written a function to do just that:
...
6
votes
1
answer
655
views
Best way to performance permutations
This has been my white whale for a while, the idea is convert all the symbols to the goal symbol using all the pieces.
I did an algorithm like 5 years ago (now is lost) and reach lvl 48 but got stuck ...
5
votes
2
answers
1k
views
Finding all possible letter combinations from an inputted phone number
Prompt:
Given a string containing digits from 2-9 inclusive, return all
possible letter combinations that the number could represent.
A mapping of digit to letters (just like on the telephone ...
3
votes
2
answers
2k
views
Generate all combinations of length N through M
I've started learning programming and as matter of practice I've decided to make a program that will output all possible string combinations and put them in a file.
I've manged to do that and it works ...
4
votes
1
answer
3k
views
K-combination recursive algorithm implementation
Tried to implement this solution for finding n choose k.
I have used recursion and this is how it goes for k as 4 and n as 6. Zero based
The idea is to have array of size k keeping sequence of ...
1
vote
1
answer
126
views
Count all possible attendance records with length n, which will be regarded as rewardable
Given a positive integer n, return the number of all possible attendance records with length n, which will be regarded as rewardable. The answer may be very large, return it after \$\mod 10^9 + 7\$.
...
3
votes
2
answers
3k
views
Non-Contiguous Substrings
Problem:
A non-contiguous substring of string \$s\$ is a sequence of \$k \geq 0\$ characters in \$s\$, in the order in which they occur in \$s\$. For instance, the set of all non-contiguous ...
6
votes
1
answer
4k
views
Permutation algorithm of N unique elements with low memory footprint
I actually had a real life need (outside work, no less) to come up with every single permutation of N elements (the N in my case being 12, so a total of ...
8
votes
2
answers
4k
views
Consecutive Primes challenge at CodeEval.com and memory allocation issue
I finally solved this challenge with using recursion and figured out why the automatic scorer wasn't passing my previous solutions. I was using NSMutableArray to ...
2
votes
1
answer
6k
views
Nsum problem: find all n elements in an array whose sum equals a given value
I am pretty new to Python, so I want to listen to any advice that improve my coding style in a "pythonic" way, even about naming style of variables. The following code reflects a very general paradigm ...
4
votes
1
answer
2k
views
Seeking improved Objective-C permutation algorithm
This algorithm seeks to find all of the possible permutations of a word:
...
8
votes
1
answer
2k
views
Speeding up subset sum implementation
Important fact: the number of the input is greater than 1. How do I use this fact to speed up this solution?
...
6
votes
2
answers
4k
views
Permutation of given string
I am reading a book on DSA, and the author explains how to generate the permutation of strings using recursion. I want to know if there are better ways of doing the same, unless this is the best ...