Count Possible Triangles | GFG | Valid Triangle Number | LeetCode | Algorithm Explanation by alGOds!
Vložit
- čas přidán 6. 06. 2020
- In this video, Vishesh Aggarwal has explained the optimized approach for calculating the #CountOfPossibleTriangles. #ValidTraingles #CountTriangles
Question Link - practice.geeksforgeeks.org/pr...
C++ Solution for Reference - ide.geeksforgeeks.org/76de47spwV
Feel free to ask any of your doubts and discuss your attempts related to this question in the comments section 😇.
Join this telegram channel for regular updates : t.me/alGOdsCZcams
Join this telegram group for doubts and discussions : t.me/joinchat/PqjeMhz0MBR-tg3...
Do like and subscribe to our channel and click the bell icon so you don’t miss any future videos!!.
Don’t forget to tell us about the Questions you need an explanatory video for in the comments section. We’ll definitely take care of it😁.
Here is the Subscription Link : / algods99
Connect with us on Gmail : algods.99@gmail.com
The contributors to this channel and their profile links are enlisted below
1) Vishesh Aggarwal:
LinkedIn :- / vishesh-aggarwal-830b5...
2) Vaibhav Varshney:
LinkedIn :- / vaibhav-varshney
3) Vagish Yagnik:
LinkedIn :- / vagish-yagnik-9203b0172
4) Vishesh Jain:
LinkedIn :- / vishesh-jain-138097174
5) Achint Dawra:
LinkedIn :- / achint-dawra-ba9550168
6) V Sriram:
LinkedIn :- / sriram-v-08b098170
7) Varun Bajlotra:
LinkedIn :- / varun-bajlotra-17715a170
8) Vikas Yadav:
LinkedIn :- / vikas-yadav-b432b5107
Join this telegram channel for regular updates : t.me/alGOdsCZcams
Join this telegram channel for doubts and discussions : t.me/joinchat/PqjeMhz0MBR-tg31OK2Dsg
if array is [1,1,1] it is returning zero sir but for these output should be 1
i think to write that check if(k>j) is not necessary because j is always going to be less than k .
Really Helpful, thanks!!
I don't understand why this line code is used after ending of while loop ??
if (k > j)
count += k - j - 1;
For fixed i and j, there are this many options for third side of triangle namely j+1, j+2, ..., k-1 which is k-j-1 in total
Thanks!
How does sorting help in this question?
For approach 2, if the array is sorted then after getting index k for some arbitrary index i and j, for i and (j+1) we can be sure that all elements from (j+2) to k are valid for forming a triangle as third side and we just have to look after the kth index.
This will help us in reducing the time complexity as discussed in the video.