You can practise the question here- bit.ly/3cqq0Dy 𝐃𝐨𝐧'𝐭 𝐜𝐥𝐢𝐜𝐤 𝐡𝐞𝐫𝐞- bit.ly/3PCiXWD Subscribe and hit the notification icon to get notifications and learn with me everyday!! ❤️❤️ #dsa #softwaredeveloper #interviewpreparation
Yes the second catch was that we had to remove the empty string from the resultant vector as it is asked in the problem statement. Thank you Mam for great teaching!!!
Hi Keerthi, These videos are really helpful. I have shared it with my friend and they subscribed to the channel. One suggestion, could you discuss time and space complexity for each of the problems that you are covering?
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sum to target. Each number in candidates may only be used once in the combination. mam could you make a video to solve this?
SUMMARY ============================= Write code for including character and excluding character Push "curr_subsequence" to "ans" when curr_idx == n Another way to remove the empty string from "ans" is to pop_back before sorting REASON: empty string will always be added to "ans" at last only Alternative code class Solution{ public: void helper(string s, int curr_idx, int n, string curr_subsequence, vector &ans){ if(curr_idx == n){ ans.push_back(curr_subsequence); return; } // include character helper(s,curr_idx+1,n,curr_subsequence+s[curr_idx],ans); // not include character helper(s,curr_idx+1,n,curr_subsequence,ans); } vector AllPossibleStrings(string s){ vector ans; helper(s,0,s.length(),"",ans); ans.pop_back(); // remove empty string sort(ans.begin(),ans.end()); return ans; } };
I wrote it like a mix of iterative + recursive manner. Please share your view point on the code. void helper(List list, String s, String sChar, int total, int counter){ char [] charArray = s.toCharArray(); if(!list.isEmpty()){ int size = list.size(); for(int i =0; i
I have one doubt mam , after include helper get executed one time ,the next exclude helper should get executed.? but in explanation according to my understanding after first helper reached to n , base condition is executing and then exclude helper.
Think of SC as an array of array, where total elems in the outer array are 2^N and each element(which is also an array of char aka string) can have max length of N. so SC will be size each elem * number of elems or O(N*2^N)