Please check my question code and help me to understand that question and give me right solution according to question.. 🙏 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Please check my question code and help me to understand that question and give me right solution according to question.. 🙏

https://code.sololearn.com/c4Teo7798Kdd/?ref=app

16th Jan 2021, 4:23 PM
Janvi Desai
3 Answers
+ 3
Thank you 😊
16th Jan 2021, 4:41 PM
Janvi Desai
+ 2
n = 3 0 1 2 (indexes) a= [3, 2, 1] In our example, the only triplet satisfying the condition is p = 0, q = 1 and r = 2 since we can clearly see p < q < r => 0 < 1 < 2 (satisfied) Also, a[p] = a[0] = 3 a[q] = a[1] = 2 a[r] = a[2] = 1 clearly, a[p]>a[q]>a[r] => a[0]>a[1]>a[2] => 3>2>1 (satisfied) Hence, the only triplet here is (p, q, r)->(0,1,2) and therefore the output is 1 since a triplet exist.
16th Jan 2021, 4:40 PM
Rohit Kh
Rohit Kh - avatar
0
n = 5 0 1 2 3 4 (indexes) a= [4, 6, 3, 1, 7] You need to display triplet(p, q, r) such that, (p<q<r and a[p]>a[q]>a[r]) is satisfied. where p, q and r are indexes in array a. In our example, the only triplet satisfying the condition is p = 1, q = 2 and r = 3 since we can clearly see p < q < r => 1 < 2 < 3 Also, a[p] = a[1] = 6 a[q] = a[2] = 3 a[r] = a[3] = 1 clearly, a[p]>a[q]>a[r] => 6>3>1 Hence, the only triplet here is (1,2,3)and therefore the output is 1 since a triplet exist.
16th Jan 2021, 4:36 PM
Rohit Kh
Rohit Kh - avatar