Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
2 votes
1 answer
75 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 ...
Thomas Mathew's user avatar
0 votes
1 answer
410 views

Generate unique string permutations recursively

🧩 Objective Write a recursive method for generating all permutations of an input string. Return them as a set. See: Recursive String Permutations - Interview Cake 🔎 Questions 1: How does the ...
adamhurwitz.eth's user avatar
2 votes
1 answer
257 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: ...
ny_coder_dude's user avatar
1 vote
1 answer
4k views

The quicksort algorithm in Haskell

I am learning Haskell programming language mainly from this source. And there I have encouraged with "an elegant" realization of the quicksort sorting algorithm (the Quick, sort! section). ...
LRDPRDX's user avatar
  • 941
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 ...
user avatar
1 vote
1 answer
337 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 ...
Anirudh Thatipelli's user avatar
1 vote
1 answer
142 views

Possible letter combinations of a dial pad in linear time using a recursive approach

Time complexity: I walk the initial unzipped array of keys representing the number O(N) backwards. I then do an inner walk of the proceeding array of letters *O(L^2), mapping it to every value in the ...
Rick's user avatar
  • 586
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): <...
committedandroider's user avatar
2 votes
1 answer
208 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 ...
CodeWriter's user avatar
2 votes
1 answer
232 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 ...
JavaDeveloper's user avatar
3 votes
5 answers
2k views

count all array[index] == index occurrences

The method foo gets a sorted list with different numbers as a parameter and returns the count of all the occurrences such that: ...
user32385's user avatar
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 ...
luckysing_noobster's user avatar
2 votes
2 answers
10k views

Fibonacci sequence implementation

This was too slow for my computer: ...
Normal People Scare Me's user avatar