3 Sum - Target Sum Unique Triplets | Leetcode 15 Solution in Hindi
HTML-код
- Опубликовано: 21 июн 2021
- Please consume this content on nados.pepcoding.com for a richer experience. It is necessary to solve the questions while watching videos, nados.pepcoding.com enables that.
NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. 1. Given an integer array 'nums', and a 'target', return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k.
2. Another thing is nums[i] + nums[j] + nums[k] == target.
3. Notice that the solution set must not contain duplicate triplets.
Topic: #twoPointerApproach, #twoSum, #Sorting
Used #DataStructure: #Arrays
#TimeComplexity: O(n^2)
#SpaceComplexity: O(1)
--------------------------------------------------------------
Linked Questions:
1. Two Sum - Target Sum Unique Pair: • 2 Sum - Target Sum Uni...
--------------------------------------------------------------
For a better experience and more exercises, VISIT: www.pepcoding.com/resources/
Have a look at our result: www.pepcoding.com/placements
Follow us on our RUclips page: / pepcoding
Follow us on our FB page: / pepcoding
Follow us on Instagram: / pepcoding
Follow us on LinkedIn: / pepcoding-education
Follow us on Pinterest: / _created
Follow us on Twitter: home
.
.
.
Happy Programming !!! Pep it up 😍🤩
.
.
.
#pepcoding #code #coder #codinglife #programming #coding #java #freeresources #datastrucutres #pepcode #competitive #competitiveprogramming #softwareengineer #engineering #engineer
Bhai bhai bhai bhai
0:24
Hope you like the video.
For better experience and well organised content sign up on nados.io and don't forget to follow us on Instagram instagram.com/pepcoding/
😂😂
threesum
F
i think time complexity analysis is also more important while writing the code, so please add tc.
sir in line number 44 why in the for loop you use i
Great explanation. Please add time complexity Analysis to videos. Thank you
Everything is precisely arranged on nados.pepcoding.com
Don't forget to follow us on Instagram instagram.com/pepcoding/
great explaination brother🔥🔥🔥
Glad you liked it, for better experience and curated content sign up on nados.io, you can also post your queries on community tab of NADOS.
Thanks Sir.
Amazing.......
Thanks for watching. Please refer to nados.pepcoding.com for best experience.
Also don't forget to follow us on Instagram.
for(int i = 0 ; i
question not available on portal
Amazing❤️❤️
Glad you liked it.
Keep learning
And for better experience and well organised content visit nados.pepcoding.com
what if the target is not given and we are asked to find the triplets in an array
please one suggetion every program u should explain about TC...
Okay
ye ques shayad rajnish sir ne bhi ek baar karay tha
Your solution will fail for following testcase - [0,0,0,0,0]
Your code will return - [[0,0,0],[0,0,0]]
Where else expected output would be - [[0,0,0]]
To fix,
if(sum == find){
ans.push_back({arr[i],arr[start],arr[end]});
while(start
hey kirtiji can you provaid full solution in c++ pls
Что ж, матан научил нас китайскому, программирование научило меня хинди
Code is not showing the desired output.
class Solution {
public List twoSum(int[] nums, int s, int e, int t) {
// 1 1 2 3 4 5 6 7 7
int start=s, end=e, target=t, sum=0;
List l = new ArrayList();
while(start < end){ // log(n)
if(start != s && nums[start] == nums[start-1]){
start++;
continue;
}
sum = nums[start] + nums[end];
if(sum == target){//element found
List l1 = new ArrayList();
l1.add(nums[start]);
l1.add(nums[end]);
l.add(l1);
start++;
end--;
}
else if(sum > target){
end--;
}
else if(sum < target){
start++;
}
}
return l;
}
public List threeSum(int[] nums) {
List l = new ArrayList();
int target = 0, oldTarget = 0, value = 0;
if(nums.length < 3){
return l;
}
Arrays.sort(nums);
for(int i=0; i
if(l != si && nums[l] == nums[l-1] ){
l++;
continue;
}
I didn't understand why l != si?
When you will do l-1 which means start-1 since l= start, so to exclude the beginning case try to think taking start as 0 you will get clear idea.
@@codersaurabh6231 Thank you!
It's showing TLE
class Solution {
public List twoSum(int arr[],int si,int ei,int target){
int left = si;
int right = ei;
List ans = new ArrayList();
while(left target){
right--;
} else {
left++;
}
}
return ans;
}
public List threeSum(int[] arr) {
Arrays.sort(arr);
int target =0;
List res = new ArrayList();
int n=arr.length;
if(n
For better insights, visit nados.pepcoding.com, post your doubts, community will help you out there.
Should have used Arrays.sort(nums) over there
In twoSum() method : if(sum==target) --> You forgot to do left++; right--;
agar main function me kaise implement kiya h , wo v batate to acha hota...qk video complete explaination wali honi chahye k .
kind of seems like u have learned the solution not a good way to explain, kindly be intuitive ;)