Print combinations of r elements in an array of size n

preview_player
Показать описание
This video explains the intuition and process behind finding combination of r elements in an array of size n. This is a very important interview backtracking problem. The CODE link is present below and the case to handle duplicates is present in the CODE file itself. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)
Рекомендации по теме
Комментарии
Автор

Commenting because this video deserves the algorithm boost

icompute
Автор

This by far is one of the best Youtube channel after iDeserve to prepare for Coding Interviews. Thanks a lot brother for all your efforts, you might not earn money from this but you'll surely earn lots of blessings cause your Videos are going to affect lots of lives.

rajattalnikar
Автор

good question, this question i got in Oracle's interview...

vinit__rai
Автор

would be great if you have explain the the code along with the picture. Specifically that tricky condition "end-i+1 >= r-index"

felix
Автор

Like you are including 2, 3 and 4 in case of 1 included, why are you not excluding 5, I know permutation would be alreasy covered but it was your logic to include and exclude every element?

HuzaifaBilal-fozc
Автор

Nice explanation just one suggestion...please try to dry run this approach with code

techie_bhuvi
Автор

one request, please cover DS, like Dp, recursion, and yes u r going good by competitive program..
keep it up....

vinit__rai
Автор

how is this part helping (end-i+1>=r-index), my main confusion is in this part, rest i have understood the logic

rounakbhattacherje
Автор

I have a question.
At the moment when we were enumerating numbers in branch 13(somewhere at 5:53), there were only two combinations, 134 and 135. But what about 132? 131? Why these two options weren't included and made in this branch?
I'd like to be explained if it's my bad and I didn't get something.

balkanhardbass
Автор

what is time complexity for this ? I have 20K record in list which are all strings . Is this the best approach i can take to make all possible combinations ?

karann
Автор

nice explanation, especially that tree diagram

goyaldeekshant
Автор

so for lets say r ranging from 0 to length of array we have to print all permutations

anuragmishra
Автор

Can we store each of these values in any array. Sir please reply.

akshat-
Автор

Can you please explain i <= end &&
end - i + 1 >= r - index

abhisheksuryavanshi
Автор

Is there a way of saving the combinations in an array apart from printing them? So if we have the set of numbers=[1, 2, 3] then combinations=[1, 2, 1, 3, 2, 3]. Thanks! Great video

claudiajimenez
Автор

I need something similar to this, but in my case the order matters (so both [1, 2] and [2, 1] would be be accepted.) Can you help me understand how it could be done?

nandotemplo
Автор

Sir try to explain through code also. Because most of the time the problem is in implementation.

yasssh
Автор

this is exactly what I wanted
thank you

siddharthjain
Автор

class Solution:
def combine(self, n: int, k: int) -> List[List[int]]:
def solve(start, curr, k):
if k == 0:
ans.append(curr[:])
return
if start == n:
return
for j in range(start, n):
curr.append(arr[j])
solve(j+1, curr, k-1)
curr.pop()

ans = []
arr = [i+1 for i in range(n)]
solve(0, [], k)
return ans

Iamnoone
Автор

Can someone tell me the time complexity of this problem

utkashyap