Question
can you show me the flowchart of this code? import java.util.Arrays; import java.util.HashSet; import java.util.Scanner; import java.util.Set; import javax.swing.JFrame; import javax.swing.JOptionPane; public class Triplesum {
can you show me the flowchart of this code?
import java.util.Arrays; import java.util.HashSet; import java.util.Scanner; import java.util.Set;
import javax.swing.JFrame; import javax.swing.JOptionPane;
public class Triplesum {
static int triplets(int[] a, int[] b, int[] c) {
int[] Adist = nodups(a); int[] Bdist = nodups(b); int[] Cdist = nodups(c);
int distinctTripletCount = 0;
Arrays.parallelSort(Adist); Arrays.parallelSort(Bdist); Arrays.parallelSort(Cdist);
for (int q : Bdist) { long c1 = getValidIndex(Adist, q) + 1; long c3 = getValidIndex(Cdist, q) + 1; distinctTripletCount += c1 * c3; } return distinctTripletCount; }
private static int [] nodups(int[] a) { Set
int result[] = new int [len]; int i = 0; for (int item : set) { result[i++] = item; } return result; }
static int getValidIndex(int[] distinctA, int key) { int low = 0; int high = distinctA.length - 1; int count = -1;
while (low <= high) { int mid = low + (high -low) / 2; if(distinctA[mid] <= key) { count = mid; low = mid + 1; }else high = mid -1; } return count; }
public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int lena = sc.nextInt(); int lenb = sc.nextInt(); int lenc = sc.nextInt();
int a[] = new int[lena]; int b[] = new int[lenb]; int c[] = new int[lenc];
for (int i = 0; i < lena; i++) { a[i] = sc.nextInt(); } for (int i = 0; i < lenb; i++) { b[i] = sc.nextInt(); } for (int i = 0; i < lenc; i++) { c[i] = sc.nextInt(); } int answer = triplets(a, b ,c);
JOptionPane.showMessageDialog(new JFrame(),answer);//System.out.println(answer); sc.close();
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started