If there is such a triplet present in array, then print the triplet and return true. We use the similar approach which i have already discussed. Helping over You can return the list of values in any order. And look at the sum. Share your suggestions to enhance the article. I have also explained this approach using a video tutorial, The link of that video tutorial is mentioned at the end of this post. Don't worry! Method 2. Examples: Example 1: Input: Helpful . I had written the code in 10 mins and then dry run the code f read more. Solve today's POTD Challenge We can also use HashSet to ignore duplicate values. On this page we will discuss two different methods for this-, Given an array which consists of only 0, 1, Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription, Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others. In this approach, we use three for loops to find all unique triplets in the array which gives the sum of zero. Method 3: This is a Hashing-based solution. The key requirement is that the sum of the three elements in the triplet is equal to the given value. WebYou task is to find the count of triplets i, j, k ( 0 i < j < k < N ), such that 'ARR[i]' + 'ARR[j]' + 'ARR[j]' is less than the value of TARGET. This article will discover the solution to the problem "Check if a triplet with the given sum exists in a binary search tree. Please refer complete article on Find a triplet that sum to a given value for more details! So, we simply run three nested loops, and pick three integers and check if they follow the property given in the problem statement( i.e for three integers a,b and c a^2 b^2 = c^2). Input format : The first line contains an Integer 't' which denotes the number of test cases or queries to be run. The steps are as follows: We will iterate the linked list and Find and return the number of distinct triplet (s) in the array/list which sum to X. I have written this code: You will be notified via email once the article is available for improvement. void findTriplets (int arr [], int n, int sum) {. Detailed solution for 3 Sum : Find triplets that add up to a zero - Problem Statement: Given an array of N integers, your task is to find unique triplets that add up to give a sum of zero. In this approach, we use three for loops to find all unique triplets in the array which gives the sum of zero. The algorithm is as follows: Find count of triplets having a sum less than or equal to b. Given an array of integers, write a code to find all unique triplets in the array which gives the sum of zero. Thank you for your valuable feedback! {1, 2, 3}) Given the array, find the maximum number of triplets that can be formed. array = {-3,0,2,3,-2} sum = 0. WebYou are given 2 numbers N and M and an array of size N. For Example : If N = 7, ARR = { 1, 5, 2, 3, 4, 6, for (int j = i + 1; j < n - 1; j++) {. We can find the answer using three nested loops for three different indexes and check if the sum of values at those indexes adds up to zero. The elements in the array need not be distinct. We can find the answer using three nested loops for three different indexes and check if the sum of values at those indexes adds up to zero. for (int k = j + 1; k < n; k++) {. It is already asked in Amazon, Facebook, Adobe and many other good companies. You can easily set a new password. Find the number of distinct triplets sums to a given integer Ask Question Asked 9 months ago Modified 9 months ago Viewed 1k times 0 You have been given a random integer array/list (ARR) and a number X. Let this count be x. WebThey are, (2, 8, 0), (2, 11, -3), (-5, 5, 10), (8, 5, -3) and (-6, 5, 11)","*/","","import java.util. Algorithm: Given an array of length n and a sum s; Create three nested loop first loop runs from start to end (loop counter i), second loop runs from i+1 to The distinct triplets are [-1,0,1] and [-1,-1,2]. Solve this sde sheet and crack DSA rounds of top MNCs. << arr [k] << endl; Approach 1. Then fix two pointers, one at i + 1 and the other at n 1. Facebook Else, if the sum of elements at two-pointer is equal to given sum then print the triplet and break. Trademarks belong to their respective owners. Oracle Interview Questions for Software Developer: Triplets with Given Sum You are given an array/list ARR consisting of N integers. *;","public class TripletSum {\t"," "," public static int tripletSum (int [] arr, int Sort the given array in ascending order using insertion sort. The most trivial approach would be to find all triplets of the array and count all such triplets whose sum = 0. Loop over the array and fix the first element of the possible triplet, arr[i]. We will use a variable 'COUNT' which will be initialized to 0, to count the number of triplets with sum X. WebTriplets with sum with given range. Method 1: This is the naive approach towards solving the above problem. BST: Search a node in Binary Search Tree : Tree Traversals: Breadth-First Search (BFS) : Tree Traversals: Depth First Search (DFS) : Construct a Binary Tree from Postorder and Inorder, Insertion in a Binary Tree (Level Order) , Construct Tree from given Inorder and Preorder traversals, Construct Tree from given Postorder and Inorder traversals, Construct Tree from given Postorder and Preorder traversal, Check If binary tree if Foldable or not.-. The time complexity of this approach is O(n^3). We can simply run three loops and generate all the possible triplets, for each triplet we can then check if its sum is less than the given target value, we can finally return the count of triplets that had a sum less than the target value (Standard Brute Force Approach!). Lets understand this WebThe sum of values given by the left half will equal arr[mi] * (mi - l + 1). WebTriplet sum You have been given a random integer array/list (ARR) and a number X. On this page we will discuss about triplet that sum to a given value in C++ . The simplest way to solve 3sum problem is by using a brute force approach. C++ code: // C++ program to evaluate the queries to calculate sum with alternating signs of array elements in a given range #include using namespace std; // Recursive function to construct Segment Tree for the subarray Find all triplets with zero sum using Sorting:. Print the array elements and the given sum. WebYou task is to find the count of triplets i, j, k ( 0 i < j < k < N ), such that 'ARR[i]' + 'ARR[j]' + 'ARR[j]' is less than the value of TARGET. If there is no triplet, then print that no triplet exist. Then run two loops to find triplets that sum to zero. WebPractice this problem. The most trivial approach would be to find all triplets of the array and count all such triplets whose sum = 0. Data Structure & Algorithm Classes (Live), Data Structure & Algorithm-Self Paced(C++/JAVA), Full Stack Development with React & Node JS(Live), Top 100 DSA Interview Questions Topic-wise, Top 20 Interview Questions on Greedy Algorithms, Top 20 Interview Questions on Dynamic Programming, Top 50 Problems on Dynamic Programming (DP), Commonly Asked Data Structure Interview Questions, Top 20 Puzzles Commonly Asked During SDE Interviews, Top 10 System Design Interview Questions and Answers, Indian Economic Development Complete Guide, Business Studies - Paper 2019 Code (66-2-1), GATE CS Original Papers and Official Keys, ISRO CS Original Papers and Official Keys, ISRO CS Syllabus for Scientist/Engineer Exam, C++ Program for Sorting all array elements except one, C++ Program to Count pairs with given sum, C++ Program for Third largest element in an array of distinct elements, C++ Program to Print uncommon elements from two sorted arrays, C++ Program to Find the subarray with least average, C++ Program for Sorting array except elements in a subarray, C++ Program for Minimum product pair an array of positive Integers, C++ Program for Pairs such that one is a power multiple of other, C++ Program to Count triplets with sum smaller than a given value, C++ Program To Remove Duplicates From A Given String, C++ Program to Find the K'th largest element in a stream, Create three nested loop first loop runs from start to end (loop counter i), second loop runs from i+1 to end (loop counter j) and third loop runs from j+1 to end (loop counter k). Find and return the triplet (s) in the array/list which sum to X. WebYou are also given an integer X .Your task is to count the number of triplets in the list that sum up to a given value X. Examples: Input: array = {12, 3, 4, 1, 6, 9}, sum = 24; Output: 12, 3, 9 Explanation: There is a triplet (12, 3 and 9) present Find the sum of ith, jth and kth element. You can return the list of values in any order. Use three nested loops, where the first loop iterates from the start to the end of the array (loop counter i), the second loop iterates from i+1 to the end of the array (loop counter j), and the third loop iterates from j+1 to the end of the array (loop counter k). Single Scan' refers to iterating over the array/list just once or to put it in other words, you will be visiting each element in the array/list just once. Input: array = {12, 3, 4, 1, 6, 9}, sum = 24;Output: 12, 3, 9Explanation: There is a triplet (12, 3 and 9) presentin the array whose sum is 24. The task at hand? A triplet is defined if it satisfies ANY ONE of the following conditions: 1) All numbers in the triplet are the same (Eg. Collaborate outside of code Explore; All features Documentation GitHub Skills The valid triplets are: (2, 2, 4), (2, 4, 6), (2, 4, 6), (4, 6, 10). The better way to solve this problem is to first sort the array. If the sum is less than the given sum_value, then perform p++. You have been given a random integer array/list (ARR) and a number X. Else return false. The following code implements this simple method using three nested loops. The problem is a standard variation of the 3SUM problem, where instead of looking for numbers whose sum is 0, we look for numbers whose sum is any constant C.. 1. if (arr [i] + arr [j] + arr [k] == sum) {. Two pointers Sort the array in non-decreasing order because after the array is sorted, we dont have to process the same elements multiple times and hence we dont have to explicitly keep track for distinct triplets. Approach: A simple method is to generate all possible triplets and compare the sum of every triplet with the given value. The counter of these loops represents the index of 3 elements of the triplets. C++ code: // C++ program to evaluate the queries to calculate sum with WebYou have been given an integer array/list(ARR) of size 'N'. Input: array = {1, 2, 3, 4, 5}, sum = 9Output: 5, 3, 1Explanation: There is a triplet (5, 3 and 1) presentin the array whose sum is 9. No.1 and most visited website for Placements in India. Web1. Manage code changes Issues. WebFind and print the triplets of elements in the array which sum to x. Web6. CognizantMindTreeVMwareCapGeminiDeloitteWipro, MicrosoftTCS InfosysOracleHCLTCS NinjaIBM, CoCubes DashboardeLitmus DashboardHirePro DashboardMeritTrac DashboardMettl DashboardDevSquare Dashboard, Instagram Plan and track work Discussions. Create a set to keep the track of triplets we have visited. All Example 2: Input: nums = [0,1,1] Output: [] Explanation: The only possible triplet does not sum up to 0. Answered May 24, 2022 Report. This is another approach to solve the given problem i.e., C++ program to find the triplets with a given sum in an array where the array is sorted. WebWe have been given an array ARR. [ [-3,0,3], [2,0,-2] ] Since 0 + 2 + (-2) = 0 and (-3) + 0 + 3 = 0, therefore the unique triplets are [-3,0,3] and [2,0,-2]. The time complexity of this approach is O(n^2). Return 0 to indicate successful execution of the program. << arr [j] << " ". For each element, use two pointers to find pairs that sum up to the given value. The most basic approach that comes to our mind is to run three nested loops {1, 1, 1}) 2) The numbers are consecutive (Eg. If the sum is less, increment the first pointer; if the sum is greater, decrement the second pointer. Write a solution to sort this array/list. Find the element that appears once in a sorted array. Note : Given array/list can contain duplicate elements. WebYou are also given an integer 'X'.Your task is to count the number of triplets in the list that sum up to a given value 'X'. Explore and share your solution to get the valuable insights from the coding community. Pair Sum [https://coding.ninja/P6] Problem Statement: Given an integer array arr of size N and an integer S. Return the list of all pairs of elements such that for each pair, the sum of elements equals S. Note: Each pair should be sortedthat is, the first value should be less than or equal to the second value. Given an array and a value, find if there is a triplet in array whose sum is equal to the given value. Brute Force Approach. The steps are as follows: We will iterate the linked list and pick each node one by one and pivot that node as the first Repeat steps 3-5 until the two pointers cross each other. This count of triplets will also include triplets having a sum less than the lower limit a. Subtract the count of triplets having a sum less than a. Linkedin Twitter, [emailprotected]+91-8448440710Text us on Whatsapp/Instagram. First we sort the array and then we run two for loops to find three elements whose sum is equal to zero. WebUnleash your inner problem-solver and get ready to tackle a new challenge. We can find the answer using three nested loops for three Given an array Arr [] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Given an array and a value, find if there is a triplet in array whose sum is equal to the given value. for (int k = j + 1; k < n; k++) {. WebThe basic idea is to initialize COUNTER:= 0 and then one by one try out all possible ways of selecting three indices, if for any triplet (i, j, k), Xor of subarray ARR[i:j-1] equal Xor of subarray ARR[j:k], then increment COUNTER by 1. Else return false. Tree Traversals: Inorder Postorder Preorder : Postorder Tree Traversal in Binary Tree : Postorder Preorder Inorder Traversal without recursion, Inorder Tree Traversal without Recursion , Preorder Tree Traversal without Recursion , Postorder Tree Traversal without Recursion . Find and return the triplet (s) in the array/list which sum to X. Your task is to find all the distinct triplets present in the array which adds up to a given number K. An array is said to have a triplet {ARR[i], ARR[j], ARR[k]} with sum = ', I have proposed two approaches one was sorting + two pointer-based and other one was map-based. basic family background, hobbies, academics, why interest in software field, questions from the ppt they presentec earlier, Triplets with Given Sum You are given an array/list ARR consisting of N integers. Naive Recursive Approach. The idea is based on the above discussed approach using Hashmap of this post. Then the test cases follow. If there is Manage code changes Issues. Made with in India. We can find the answer using three nested loops for three different indexes and check if the values at Print the triplet and break. Brute Force Approach. It only contains 0s, 1s and 2s. Lets write a code to find all unique triplets with zero sum using HashSet. Also, the ordering of different triplets can be random i.e if there are more than one valid triplets, you can return them in any order. Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. By using our site, you If the sum is equal to given sum. If there is such a triplet present in array, then print the triplet and return true. This sde sheet will help you prepare for your subsequent prominent placement! WebStriver SDE Sheet contains the most popular coding questions asked during SDE interviews. Copyright 2020 2021 webrewrite.com All Rights Reserved. Finding a triplet of values in a BST that adds up to a given sum, but with a twist doing it in the most efficient way possible. Java Program to Find a triplet that sum to a given value. for (int i = 0; i < n - 2; i++) {. sorting approach: The sorting approach involves sorting the given array and then using two pointers to find triplets that sum to the given value C++.This approach has a time complexity of O(n^2), where n is the size of the array. ","That is, if a valid triplet is (6, 5, 10) print \"5 6 10\". Rank 1 (AkashSingh3031) - C++ (g++ 5.4) Solution. There is no constraint that out of 5 triplets which have to be printed on 1st line. job seekers every month in choosing their right fit company. 3. If no triplet is found with the given sum, print No triplet exists. Algorithm: Sort the given array in ascending order using insertion sort. We can find the answer using three nested loops for three different indexes and check if the values at those indexes sum up to 'K'. A triplet that sums to a given value C is a set of three elements in an array whose sum is equal to C. We will this in detail we different methods along with algorithm and code in C++ . The most trivial approach would be to find all triplets of the array and count all such triplets whose sum = 0. Contribute to the GeeksforGeeks community and help create better learning resources for all. [ [-3,0,3], [2,0,-2] ] Since 0 + 2 + (-2) = 0 and (-3) + 0 + 3 = 0, therefore the unique triplets are [-3,0,3] and [2,0,-2]. WebGiven an array Arr [] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. If the sum is equal to the given sum, print the triplet and break out of the loops. Our task is to minimize the sum of minimum and second minimum elements from all possible triplets in the array, with the constraint that a single element can be part of only one triplet. A triplet that sums to a given value is a set of three elements in an array whose sum is equal to the given value. 2. We will use a variable 'COUNT' which will be initialized to 0, to count the number of triplets with sum X. WebWrite better code with AI Code review. Call the function recursively to get the sum of left and right subtree and then return their sum. The time complexity of this approach is O (n^3). If the sum is greater than the given sum_value, then perform q--. In short, you need to return an array of all the unique triplets [arr[a], arr[b], arr[c]] such that i!=j, j!=k, k!=i, and their sum is equal to zero. For example, if we have an array [1, 2, 3, 4, 5] and the target sum is 9, then a triplet that sums to 9 could be (2, 3, 4) or (1, 2, 6), as both sets of elements add up to 9. The triplets are generated between a given range and the value of the range is altered based on the given sum value. Time complexity: O(n^2) Program to find all the triplets with the given sum using the sorting technique (loop counter i). For every element check that there The steps are as follows : WebGiven an array Arr [] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Practice Video Given an array and a value, find if there is a triplet in array whose sum is equal to the given value. Checkout list of all the video courses in PrepInsta Prime Subscription, Binary Tree in Data Structures (Introduction), Binary search tree in Data Structures (Introduction), If OTP is not received, Press CTRL + SHIFT + R, AMCAT vs CoCubes vs eLitmus vs TCS iON CCQT, Companies hiring from AMCAT, CoCubes, eLitmus, Inorder Postorder PreOrder Traversals Examples. Youtube Practice Video Given an array and a value, find if there is a triplet in array whose sum is equal to the given value. rights reserved 2023 Info Edge (India) Ltd. Q1. Find a peak element in an array. 85 Lakh The idea is similar to the 01 Knapsack problem and uses recursion.We either consider the current item or exclude it and recur for the remaining Run another loop from i+1 to end of the array. If you know any other approach to solve this problem efficiently then let us know through your comments. Here is a list of Strivers-SDE-sheet problems people have successfully solved to land their dream jobs. WebThey are, (2, 8, 0), (2, 11, -3), (-5, 5, 10), (8, 5, -3) and (-6, 5, 11)","*/","","import java.util. We are using HashSet to solve this problem because it does not allow duplicates and its lookup time is O(1). WebExample 1: Input: nums = [-1,0,1,2,-1,-4] Output: [ [-1,-1,2], [-1,0,1]] Explanation: nums [0] + nums [1] + nums [2] = (-1) + 0 + 1 = 0. nums [1] + nums [2] + nums [4] = 0 + 1 + (-1) = 0. nums [0] + nums [3] + nums [4] = (-1) + 2 + (-1) = 0. Algorithm WebWrite better code with AI Code review. Java Program to Find a triplet that sum to a given value, Python3 Program to Find a triplet that sum to a given value, Javascript Program to Find a triplet that sum to a given value, Python Program for Find a triplet from three linked lists with sum equal to a given number, C++ Program to Find a triplet such that sum of two equals to third element, Java Program to Find a triplet such that sum of two equals to third element, Python Program to Find a triplet such that sum of two equals to third element, Php Program to Find a triplet such that sum of two equals to third element, Javascript Program to Find a triplet such that sum of two equals to third element, Mathematical and Geometric Algorithms - Data Structure and Algorithm Tutorials, Learn Data Structures with Javascript | DSA Tutorial, Introduction to Max-Heap Data Structure and Algorithm Tutorials, Introduction to Set Data Structure and Algorithm Tutorials, Introduction to Map Data Structure and Algorithm Tutorials, A-143, 9th Floor, Sovereign Corporate Tower, Sector-136, Noida, Uttar Pradesh - 201305, We use cookies to ensure you have the best browsing experience on our website. For example, if a valid triplet is {1, 2, -3}, then {2, -3, 1}, {-3, 2, 1} etc is also valid triplet. If there is such a triplet present in array, then print Else return false. A triplet that sums to a given value is a set of three elements in an array whose sum is equal to the given value. There were two technical rounds followed by a managerial and hr round.The first round was highly technical and questions were asked on string data str, Q2. Prompt the user to enter an integer value, lets call it o. Also, the ordering of different triplets can be random i.e if there are more than one valid triplets, you can return them in any order. Help us improve. If the sum exceeds the given sum, we move the pointer to the larger element toward the left. WebThe distinct triplets are [-1,0,1] and [-1,-1,2]. Given an array and a value, find if there is a triplet in array whose sum is equal to the given value. For example, if a valid triplet is {1, 2, -3}, then (2, -3, 1), (-3, 2, 1) etc is also valid triplet. The elements in the array need not be distinct. In this approach,we for (int i = 0; i < n - 2; i++) {. Algorithm: We will set totalTriplets as 0. Traverse the array from start to end. Find triplets with zero sum (3Sum Problem). WebYou are given 2 numbers N and M and an array of size N. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Input format : The first line contains an Integer 't' which denotes the number of test cases or queries to be run. WebThe above code has a time complexity of O (n^3). Enhance the article with your expertise. If there is such a triplet present in array, then print the triplet and return true. We repeat these steps until we find a triplet with the given sum or until the two pointers meet. The most trivial approach would be to find any triplet in the array such that two of its elements sums up to the third element. ","While printing a triplet, print the smallest element first. WebHere are the top solutions of POTD Challenge. void findTriplets (int arr [], int n, int sum) {. Create a HashMap or set to store unique pairs. Java Program to Find a triplet that sum to a given value. The valid triplets are: (2, 2, 4), (2, 4, 6), (2, 4, 6), (4, 6, 10). For example, if we have an array [1, 2, 3, 4, 5] and the In this approach,we basically need to find three indexes which satisfy the condition A In this tutorial, I have explained multiple approaches and its time complexities to solve this problem. Finding a triplet of values in a BST that adds up to a given sum, but with a twist doing it in Telegram WebYour task is to find all the distinct triplets present in the array which adds up to a given number K. An array is said to have a triplet {ARR[i], ARR[j], ARR[k]} with sum = 'K' if there exists three indices i, j and k such that i!=j, j!=k and i!=j and ARR[i] + ARR[j] + ARR[k] = 'K'. (loop counter j), If there is an element in the set which is equal to x- arr[i] arr[j], then print the triplet (arr[i], arr[j], x-arr[i]-arr[j]) and break. Notice that the order of the output and the order of the triplets does not matter. The loop counters i, j, and k represent the indices of the three elements in the triplet. The variable totalTriplets stores the total number of triplets following the given conditions. A triplet that sums to a given value is a set of three elements in an array whose sum is equal to the given value. Iterate through the array from the beginning till the third-to-last element. WebNote: 1. The other advantage of sorting the array is, Oracle Software Developer Interview Questions. cout << arr [i] << " ". We can simply run three loops and generate all the possible triplets, for each triplet we can then check if its sum is less than the given target value, we can finally return {1, 1, 1}) Example 1: Input: N = 4 Arr = {8 , 3, 5, The simplest way to solve 3sum problem is by using a brute force approach. CodingNinjas. Collaborate outside of code Explore; All features Documentation GitHub Skills CodingNinjas-Tricky-Ques / Triplet Sum Go to file Go to file T; Go to line L; Copy path Time Complexity: O(n 2), Since two nested loops are required, so the time complexity is O(n 2). In this tutorial, I am going to discuss multiple approaches and their time complexities to solve this problem efficiently. Hey everyone, creating this thread to discuss the interview problem - Count triplets in a sorted doubly linked list whose sum is equal to a given value x. Practise this interview question on CodeStudio (hyperlinked with the following link): Count triplets in a sorted doubly linked list whose sum is equal to a given value x If the sum is smaller than the required sum, increment the first pointer. WebIf the sum of these elements is lesser than the given sum, we move the pointer to the smaller element toward the right. Note : Given array/list can contain duplicate elements. Sorting algorithms and their time complexities. This problem is very important in terms of interviews. Take n integer inputs from the user to populate the array. Contribute your expertise and make a difference in the GeeksforGeeks portal. Repeat steps 4 to 6. Note: The solution set must not contain duplicate triplets. Lets implement the second approach to solve 3 sum problem using java code. 3. In this approach, to ignore duplicates we have explicitly checked consecutive indices with same value. WebYour task is to find all the distinct triplets present in the array which adds up to a given number K. An array is said to have a triplet {ARR[i], ARR[j], ARR[k]} with sum = 'K' if there Hand shaking lemma and some Impotant Tree Properties. WebYou are also given an integer X .Your task is to count the number of triplets in the list that sum up to a given value X. Managerial round will be a formal discussion with the interviewer regarding the role,what roles you have worked in your previous organization, questio, Q3. Auxiliary Space: O(n), Since a HashSet is required, so the space complexity is linear. Else, If the sum is bigger, Decrease the end pointer to reduce the sum. Prompt the user to enter the size of the array and store it in a variable, lets call it n. I had written the code in 10 mins and then dry run the code f. Brute Force The most trivial approach would be to find all triplets of the array and count all such triplets whose SUM = 'K'. We help students to prepare for placements with the best study material, online classes, Sectional Statistics for better focus andSuccess stories & tips by Toppers on PrepInsta. WebUnleash your inner problem-solver and get ready to tackle a new challenge. acknowledge that you have read and understood our. To obtain type 2 triplets, we will traverse through ARR2 and we will consider all pairs from ARR1 and check if the element from ARR2 and the pair from ARR1 follow the given conditions of type 2 triplet.