All Questions
7 questions
2
votes
1
answer
72
views
Merge Sort with Minimum Sufficient Variables, Verbosity and better Space Complexity
The majority of merge sort implementations searched online are provided with unnecessary variables and code lines. Here is an attempt to reduce that. However, does passing back the subArray as return ...
1
vote
1
answer
3k
views
Finding pairs that add up to a given sum, using recursion
I'm currently tasked with using recursion to find pairs that add up to a given sum. How would I make the function recursiveFixedSumPairs function more efficient and truncate this code? Also, what is ...
1
vote
1
answer
335
views
Rearrange an array in place such that the first and last halves are interleaved
Given an array of n elements in the following format { a1, a2, a3, a4,
….., an/2, b1, b2, b3, b4, …., bn/2 }. The task is shuffle the array
to {a1, b1, a2, b2, a3, b3, ……, an/2, bn/2 } without ...
5
votes
2
answers
2k
views
Non-recursive method for finding \$a^n\$
I am working on an interview question from Amazon Software. The particular question I am working on is "to write a program to find \$a^n\$."
Here is my recursive solution to this problem (in Java):
<...
2
votes
1
answer
199
views
Time complexity of 0/1 Knapsack challenge
The code gives correct output. How do I calculate time complexity for code like this?
The program finds all the combinations of items and sees if the combination gives the max profit. If the last ...
2
votes
1
answer
227
views
Given set of cubes can we get a given word?
Given some cubes, can cubes be arranged such that an input word can be formed from the top view of the cubes?
For example: assume an imaginary cube with only 3 surfaces where ...
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 ...