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...
-
What are the five major project fundamentals?
-
Martin sells a stock investment for $26,000 on August 2, 2018. Martins adjusted basis in the stock is $15,000. a. If Martin acquired the stock on November 15, 2017, calculate the amount and the...
-
Place the corresponding letter of the definition next to the term. a. An organization that stands as a separate economic unit must not have its financial affairs confused with that of other entities....
-
Combined data for three years for two firms appear below (in millions). One of these firms is Amazon.com, a rapidly growing internet retailer, and the other is Kroger, a retail grocery store chain...
-
One year ago, you had acquired Tesla Inc, USA for US$50.00 per share. The current price is US$60.00 and during the year, you received 3 dividend payments totalling US$15.00. Calculate the following:...
-
Amazon Wood Products, Inc. is a manufacturer of fine quality tables, chairs, and desks. The following information relates to expected production, sales, and other costs for next year (ended December...
-
Your manager is concerned that costs are being misappropriated due to large balances in ending work in process inventories while currently using the FIFO Method for accounting for beginning work in...
-
Flint Company sponsors a defined benefit pension plan for its employees. The following data relate to the operation of the plan for the year 2020 in which no benefits were paid. 1. The actuarial...
-
As Superintendent Field, how can you align the strategic objectives of the National Park Service with the redevelopment of Caneel Bay? Given the mission of the National Park Service, which...
-
Beginning inventory is 1 0 0 0 units which cost $ 2 5 each. During the month, 4 0 0 0 units were purchased for $ 2 9 each. 3 6 0 0 units were sold for $ 6 0 each. How much more ( less ) would income...
-
What is the principal economic definition of a natural monopoly, and what issues arise from this situation in the energy sector? Examine and compare the economics of the regulatory approaches that...
-
Martin Clothing Company is a retail company that sells hiking and other outdoor gear specially made for the desert heat. It sells to individuals as well as local companies that coordinate adventure...
-
if there is a $100,000 1st mortgage on a residential property that is current (not delinquent), and a $50,000 2nd mortgage that is seriously delinquent, should the 2nd mortgage lender foreclose if...
-
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...
-
Examine the financial data of Black Corporation. Show how to compute Black's current ratio from 2018 to 2020. Is the company's ability to pay its current liabilities improving or deteriorating? 1 23...
-
Vision Software Limited reported the following amounts on its balance sheets at December 31, 2020, 2019, and 2018: Sales and profits are high. Nevertheless, Vision is experiencing a cash shortage....
-
Use the Allstott, Inc., balance sheet data below. 1. Compute Allstott, Inc.'s quick (acid-test) ratio at December 31, 2020 and 2019. 2. Use the comparative information from the table on page 597 for...
Study smarter with the SolutionInn App