Doug's Difference Doug was doing his math homework with two of his friends, at one point...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Doug's Difference Doug was doing his math homework with two of his friends, at one point they all got bored but Doug had an idea to pass the time in an interesting way he decided to play a game of difference such that - Given a sequence of integers a, a triplet (a[i],a[i],a[k]) is beautiful if: 1.i<j<k 2. all-all-a[k]-a[j] = d Given an increasing sequence of integers and the value of d, count the number of beautiful triplets in the sequence. Function Description Complete the beautifulTriplets function in the editor below. beautifulTriplets has the following parameters: int d: the value to match int arr[n]: the sequence, sorted ascending Returns int: the number of beautiful triplets Input Format 1- import java.io.*; 2 import java.util."; import java.text."; 3 4 import java.math."; 5 6 7 8 9 10- 11 import java.util.regex."; public class Main ( 12 13 14- 15 16 17 18 19 20 21 22 23 24 25 ) static void getCount (int[] a, int n, int diff) ( // write your code here. } public static void main(String[] args) { /* Enter your code here. Read input from STDIN, Print output Scanner sc = new Scanner(System.in); } int n sc.nextInt (); - int diff sc.nextInt(); Int a[]- new int[n]; for(int i-0;i<n;i++) a[1] sc.nextInt(); getCount(a,n, diff); I Ac Go <epam> EPAM Coding Question No. 1 of 1|| 20 Marks int: the number of beautiful triplets 1.1<-<- 10^4 2.1<-d<-20 https://mymapit.in/#/test/247358848?testPackid=undefined Input Format The first line contains 2 space-separated integers, n and d, the length of the sequence and the beautiful difference. The second line contains n space-separated integers arr[i]. Constraints- 3.0<= arr[i]<=2*10^4 4. arr[i]> arr[i-1] Sample Input-STDIN 73 12457810 Function arr[] size n=7, d = 3 arr = [1, 2, 4, 5, 7, 8, 10] 71-41-2-d Caution! Please do not move away from th A Next Question Sample Output 3 Explanation. There are many possible triplets (arr[i],arrj], arr[k]), but our only beautiful triplets are (1,4,7) ,(4,7,10) and (2,5,8) by value, not index. Please see the equations below: JAVA 9 10- 11 12 13 14. 15 16 17 18 19 20 21 22 23 24 25 ← → CO <epam> Coding Question No. 1 of 1 || 20 Marks Sample Output 3 arr[] size n-7, d-3 arr- [1, 2, 4, 5, 7, 8, 10] 7-4-4-1-3-d 10-7-7-4-3-d 8-5-5-2=3=d Sample Input https://mymapit.in/#/test/247358848?testPackid=undefined Explanation. There are many possible triplets (arr[i],arr[j],arr[k]), but our only beautiful triplets are (1,4,7) , (4,7,10) and (2,5,8) by value, not index. Please see the equations below: 73 EPAM 124578 10 Sample Input 10 3 16 7 7 8 10 12 13 14 19 Sample Output 3 Sample Output 2 " D Caution Please do not move away from the window or refresh, you may be marked as suspicious Next Question JAVA (1.8) 1 import java.io.*; 2 3 4 5 6 7 8 9 10-> 11 12 13. H5Ep12345 16 17 18 19 20 22 Import java.util."; import java.text."; import java.math."; import java.util.regex.*; public class Main ( static void getCount(int[] a, int n, int diff) ( } Ma I write your code here. Ⓒ00:26 public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output Scanner sc new Scanner(System.in); int n sc.nextInt(); int diff sc.nextInt(); int a[]- new int[n]; for(int 1-8;i<n;i++) a[1] sc.nextInt(); getCount(a,n,diff); Doug's Difference Doug was doing his math homework with two of his friends, at one point they all got bored but Doug had an idea to pass the time in an interesting way he decided to play a game of difference such that - Given a sequence of integers a, a triplet (a[i],a[i],a[k]) is beautiful if: 1.i<j<k 2. all-all-a[k]-a[j] = d Given an increasing sequence of integers and the value of d, count the number of beautiful triplets in the sequence. Function Description Complete the beautifulTriplets function in the editor below. beautifulTriplets has the following parameters: int d: the value to match int arr[n]: the sequence, sorted ascending Returns int: the number of beautiful triplets Input Format 1- import java.io.*; 2 import java.util."; import java.text."; 3 4 import java.math."; 5 6 7 8 9 10- 11 import java.util.regex."; public class Main ( 12 13 14- 15 16 17 18 19 20 21 22 23 24 25 ) static void getCount (int[] a, int n, int diff) ( // write your code here. } public static void main(String[] args) { /* Enter your code here. Read input from STDIN, Print output Scanner sc = new Scanner(System.in); } int n sc.nextInt (); - int diff sc.nextInt(); Int a[]- new int[n]; for(int i-0;i<n;i++) a[1] sc.nextInt(); getCount(a,n, diff); I Ac Go <epam> EPAM Coding Question No. 1 of 1|| 20 Marks int: the number of beautiful triplets 1.1<-<- 10^4 2.1<-d<-20 https://mymapit.in/#/test/247358848?testPackid=undefined Input Format The first line contains 2 space-separated integers, n and d, the length of the sequence and the beautiful difference. The second line contains n space-separated integers arr[i]. Constraints- 3.0<= arr[i]<=2*10^4 4. arr[i]> arr[i-1] Sample Input-STDIN 73 12457810 Function arr[] size n=7, d = 3 arr = [1, 2, 4, 5, 7, 8, 10] 71-41-2-d Caution! Please do not move away from th A Next Question Sample Output 3 Explanation. There are many possible triplets (arr[i],arrj], arr[k]), but our only beautiful triplets are (1,4,7) ,(4,7,10) and (2,5,8) by value, not index. Please see the equations below: JAVA 9 10- 11 12 13 14. 15 16 17 18 19 20 21 22 23 24 25 ← → CO <epam> Coding Question No. 1 of 1 || 20 Marks Sample Output 3 arr[] size n-7, d-3 arr- [1, 2, 4, 5, 7, 8, 10] 7-4-4-1-3-d 10-7-7-4-3-d 8-5-5-2=3=d Sample Input https://mymapit.in/#/test/247358848?testPackid=undefined Explanation. There are many possible triplets (arr[i],arr[j],arr[k]), but our only beautiful triplets are (1,4,7) , (4,7,10) and (2,5,8) by value, not index. Please see the equations below: 73 EPAM 124578 10 Sample Input 10 3 16 7 7 8 10 12 13 14 19 Sample Output 3 Sample Output 2 " D Caution Please do not move away from the window or refresh, you may be marked as suspicious Next Question JAVA (1.8) 1 import java.io.*; 2 3 4 5 6 7 8 9 10-> 11 12 13. H5Ep12345 16 17 18 19 20 22 Import java.util."; import java.text."; import java.math."; import java.util.regex.*; public class Main ( static void getCount(int[] a, int n, int diff) ( } Ma I write your code here. Ⓒ00:26 public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output Scanner sc new Scanner(System.in); int n sc.nextInt(); int diff sc.nextInt(); int a[]- new int[n]; for(int 1-8;i<n;i++) a[1] sc.nextInt(); getCount(a,n,diff);
Expert Answer:
Related Book For
Microeconomics An Intuitive Approach with Calculus
ISBN: 978-0538453257
1st edition
Authors: Thomas Nechyba
Posted Date:
Students also viewed these programming questions
-
Solve in python Q3: Filter a list (20 marks) Suppose you are given a list of marks, please write a function filter_mark(marks, grade) that takes a list of marks as input and return a list contianing...
-
Metro Land is a country located on a 2D Plane. They are having asummer festival for everyone in the country and would like tominimize the overall cost of travel for their citizens. Costs oftravel are...
-
Solve using Python spyder. The airline_delay on the right is just a snapshot of the file. explain in steps. Origin Airport: LGA STEP 1 Flights from LGA was on time 5033 times. Flights from LGA was...
-
Education is a very important job because it can change and shape people's lives. It gives people the knowledge, skills, and attitudes they need to be successful in their personal and work lives. As...
-
Using an Internet search engine, search for strategic alliance, and identify three recently formed alliances. For each alliance, identify whether the companies other products are generally...
-
Consider the following excerpt from an article published in Forbes: The Supersolvent No longer is it a mark of a fuddy-duddy to be free of debt. There are lots of advantages to it. One is that you...
-
If career opportunities in an organization are limited, do managers have a responsibility to convey this information to employees? Explain your position.
-
Linda Filasky held policies issued by Preferred Risk Mutual Insurance Co. Following an injury in an automobile accident and storm damage to the roof of her home, Filasky sustained loss of income,...
-
You manage a risky portfolio with an expected rate of return of 1 0 % and a standard deviation of 2 0 % . The Treasury bill ( risk - free security ) rate is 5 % . Suppose that your client prefers to...
-
A job shop consists of 6 different machines and 4 different jobs are to be processed through these machines. The job interarrival time follows Exp(15) mins. Each job is processed on a series of...
-
Bahrain Car Parks Company B.S.C. (Bahrain Bourse, #CPARK) has the information shown below (all numbers are in thousands Sales Cost of Goods Sold Accounts Receivable Inventory Total current assets...
-
You have the following information for the Swiss power and automation technology firm, ABB Ltd. All figures are in millions of Swiss francs (SFr). Give a brief interpretation of what you think ABB...
-
Your current salary is a fixed sum of $115,600 per year. You have an offer for another job. The salary there is a flat $75,000 plus a chance to earn $350,000 if the company does well. Assume that...
-
Genetic Engineering Research Studies Ltd (GERS) has hired you as a consultant to evaluate the NPV of its proposed toad house. GERS plans to breed toads and sell them as ecologically desirable insect...
-
Annie, Blake, and Cornelia are triplets who are trying to decide on a name for their new bakery. They have narrowed their decision down to three choices, and the preferences of each are listed in the...
-
Sony International has an investment opportunity to produce a new 100-inch widescreen TV. The required investment on 1 January of this year is $32 million. The firm will depreciate the investment to...
-
How many units would the company have needed to sell to produce a profit of P12,000?* [ NUBD Corporation manufactures and sells two products: A123 and B456. The operating results of the company are...
-
Use of the contraceptive Depo Provera appears to triple women's risk of infection with chlamydia and gonorrhea , a study reports today. An estimated 20 million to 30 million women worldwide use Depo...
-
In this exercise, we are working with the concept of an elasticity of substitution. This concept was introduced in part B of the Chapter. Thus, this entire question relates to material from part B,...
-
Pollution Taxes on Output: Suppose you are one of many firms that refine crude oil into gasoline. Not surprisingly, this process is one that creates pollution. The government therefore announces a...
-
Federal anti-trust laws prohibit many forms of collusion in price setting between firms. Labor unions, however, are exempt from anti-trust laws and are allowed to use market power to raise wages for...
-
Explain why and how the government intervenes in the financial system, and the problems the government safety net creates.
-
Identify the sources and discuss the consequences of bank runs, bank panics, and financial crises.
-
In the absence of limits on the behavior of large intermediaries, how might the perception of institutions being too-big-to-fail lead to increased concentration in the banking industry?
Study smarter with the SolutionInn App