Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 set = new HashSet<>(); for (int item : a) { set.add(item); } int len = set.size();

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is the relationship between diversity, inclusion, and equity?

Answered: 1 week ago