5. Reverse Array Queries For a given array of integers, perform operations on the array. Return...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
5. Reverse Array Queries For a given array of integers, perform operations on the array. Return the resulting array after all operations have been applied in the order given. Each operation contains two indices. Reverse the subarray between those zero-based indices, inclusive. Example arr= [5, 3, 2, 1, 3] operations=[[0, 1], [1, 3]] In the first operation, reverse the subarray from arr[0] through arr[1]: arr' = [3, 5, 2, 1, 3] In the second operation, reverse the subarray from arr[1] through arr[3]: arr"=(3, 1, 2, 5, 3] All operations have been performed, so return the array [3, 1, 2, 5,3]. Function Description Complete the function performOperations in the editor below. The function has the following parameter(s): int arrin): an array of integers int operations[q][2]. a 2-dimensional array of starting and ending indices Returns: int[n]: the final array after all operations have been performed Constraints • 1 ≤n. qs 10³ • 1 s arr[] ≤ 10³ • 0≤ operations[i][0] ≤ operations[i][1]<n Language C Autocomplete Ready 20 21 22 23 24 25 26 27 28 29 30 31 33 34 35 36 37 38 39 40 41 42 43 44 45 46 /* * Complete the 'performOperations' function below. * * The function is expected to return an INTEGER ARRAY. * The function accepts following parameters: * 1. INTEGER ARRAY arr 2. 2D INTEGER ARRAY operations /* * To return the integer array from the function, you should: * - Store the size of the array to be returned in the result_count variable * * * For example, * int* return_integer_array_using_static_allocation (int* result_count) { *result_count = 5; * * * ★ * Allocate the array statically or dynamically * Tast static int a[5]= {1, 2, 3, 4, 5); * * int* return_integer_array_using dynamic_allocation (int* result_count) { *result_count = 5; return a; Custom MOMENTS Run Code ⠀ Run Tests Line: 20 Col: 1 Submit ▾ Sample Case 0 Sample Input STDIN ---- 3A23 MA 1 2 WIN 1 Function 1 1 1 ----- → arrl] size n = 3 arr = [1, 2, 3] → Sample Output operations [] size q = 3 operations [q] [] size columns = 2 (always = 2) operations = [[0, 2], [1, 2], [0, 2]] Explanation The original array arr = [1, 2,3]. Reverse arr[0] through arr[2]: arr' = [3, 2. 1]. Reverse arr[1] through arr[2]: arr" = [3, 1, 2]. Reverse arr"[0] through arr"[2]: arr" = [2, 1,3]. ▾ Sample Case 1 Sample Input STDIN NHUNGA 11 5521 Function arrt] size n = 4 arr = [5, 2, 5, 1] → operations [] size q = 2 → operations [q] [] size columns = 2 ➜ operations = [[1, 2], [1, 1]] Sample Output Explanation The original array arr = [5, 2, 5, 1]. Reverse arr[1] through arr[2]: arr' = [5. 5. 2. 1]. Reverse arr[1]through arr[1]: arr" = [5, 5. 2. 1]. 5. Reverse Array Queries For a given array of integers, perform operations on the array. Return the resulting array after all operations have been applied in the order given. Each operation contains two indices. Reverse the subarray between those zero-based indices, inclusive. Example arr= [5, 3, 2, 1, 3] operations=[[0, 1], [1, 3]] In the first operation, reverse the subarray from arr[0] through arr[1]: arr' = [3, 5, 2, 1, 3] In the second operation, reverse the subarray from arr[1] through arr[3]: arr"=(3, 1, 2, 5, 3] All operations have been performed, so return the array [3, 1, 2, 5,3]. Function Description Complete the function performOperations in the editor below. The function has the following parameter(s): int arrin): an array of integers int operations[q][2]. a 2-dimensional array of starting and ending indices Returns: int[n]: the final array after all operations have been performed Constraints • 1 ≤n. qs 10³ • 1 s arr[] ≤ 10³ • 0≤ operations[i][0] ≤ operations[i][1]<n Language C Autocomplete Ready 20 21 22 23 24 25 26 27 28 29 30 31 33 34 35 36 37 38 39 40 41 42 43 44 45 46 /* * Complete the 'performOperations' function below. * * The function is expected to return an INTEGER ARRAY. * The function accepts following parameters: * 1. INTEGER ARRAY arr 2. 2D INTEGER ARRAY operations /* * To return the integer array from the function, you should: * - Store the size of the array to be returned in the result_count variable * * * For example, * int* return_integer_array_using_static_allocation (int* result_count) { *result_count = 5; * * * ★ * Allocate the array statically or dynamically * Tast static int a[5]= {1, 2, 3, 4, 5); * * int* return_integer_array_using dynamic_allocation (int* result_count) { *result_count = 5; return a; Custom MOMENTS Run Code ⠀ Run Tests Line: 20 Col: 1 Submit ▾ Sample Case 0 Sample Input STDIN ---- 3A23 MA 1 2 WIN 1 Function 1 1 1 ----- → arrl] size n = 3 arr = [1, 2, 3] → Sample Output operations [] size q = 3 operations [q] [] size columns = 2 (always = 2) operations = [[0, 2], [1, 2], [0, 2]] Explanation The original array arr = [1, 2,3]. Reverse arr[0] through arr[2]: arr' = [3, 2. 1]. Reverse arr[1] through arr[2]: arr" = [3, 1, 2]. Reverse arr"[0] through arr"[2]: arr" = [2, 1,3]. ▾ Sample Case 1 Sample Input STDIN NHUNGA 11 5521 Function arrt] size n = 4 arr = [5, 2, 5, 1] → operations [] size q = 2 → operations [q] [] size columns = 2 ➜ operations = [[1, 2], [1, 1]] Sample Output Explanation The original array arr = [5, 2, 5, 1]. Reverse arr[1] through arr[2]: arr' = [5. 5. 2. 1]. Reverse arr[1]through arr[1]: arr" = [5, 5. 2. 1].
Expert Answer:
Related Book For
Accounting Principles
ISBN: 978-0470533475
9th Edition
Authors: Jerry J. Weygandt, Paul D. Kimmel, Donald E. Kieso
Posted Date:
Students also viewed these electrical engineering questions
-
Mail-Raasika Tago.... M Gmail of 4 Q 196900 VIN PAYPA YouTube Bath Moodle Home: Panopto Ba... ET VIRTU MAAPARA ETS 4. Explain how the European Central Bank (ECB) has implemented a policy of negative...
-
Draw the schematic diagram of the difference equation with explanation: y(n) = 0.75x(n)-0.45x(n-1)-1.5x(n-2) +1.5x(n-3)- 0.15y(n-3) -1.25y(n-2) +0.75y(n-1).
-
please solve them as soon as possible 3) Imagine that firms produce shirts and that producing each shirt generates a\ \ negative externality, which we will call pollution. \ \ a. Draw supply and...
-
Write a program that takes the name of a .wav file and a playback rate r as command-line arguments and plays the file at the given rate. First, use StdAudio.read() to read the file into an array a[]....
-
Read the following five independent sampling applications. Required: Indicate whether each situation is characteristic of sampling risk (S) or non-sampling risk (N). Provide a brief explanation for...
-
Consider a thin opaque, horizontal plate with an electrical heater on its backside. The front side is exposed to ambient air that is at 20C and provides a convection heat transfer coefficient of 10...
-
What is the plain-meaning rule?
-
The following selected transactions were completed by Amsterdam Supply Co., which sells office supplies primarily to wholesalers and occasionally to retail customers. Also note that the company uses...
-
The database contains three tables containing information about this company's sales process: Inventory, Sales, and SalesItems. Use the Relationships window to link the tables together. The...
-
Based on the information in The Art of Positive Communication EL. a TedTalk by Julien Mirivel, Answer the following questions: 1) Name and give a brief example for each of the 6 positive...
-
Project Management Essentials - Closing Video: https://youtu.be/MWu8B8rcS2g Answer Questions Below: 1.What are actions for the project team during the closing of a project? 2.What are the outcomes of...
-
Raymond won a gold medal at the Tokyo Olympics for archery. As a result the US Olympic Committee awarded him $35,000. He also received $200,000 from an endorsement with archery sport company. He will...
-
You tract the market price of the T-bill on the firts of each month during the year. Below is the data. Suppose you had sold the T-bill after 5 months on November 1, 2014 for $994.29. What would you...
-
In what ways does cognitive moral development theory provide insights into the cognitive processes underlying ethical decision-making and the development of personal and organizational integrity?
-
1. What type of furniture and fixtures will you utilize in a makeup store? 2. Describe your store layout in detail of a makeup store. 3. Describe the advantages and disadvantages of the layout you...
-
Sage One vs. Quickbooks Online Document similarities, differences, express the features or qualities you appreciate in one system compared to the other and provide reasoning for the preference.
-
You are trying to demonstrate the cost of credit card interest to a client. Assume the client spends $100 per month on their credit card for 5 years and makes no interest or principal payments (i.e....
-
In the current year, the City of Omaha donates land worth $500,000 to Ace Corporation to induce it to locate in Omaha and create an estimated 2,000 jobs for its citizens. a. How much income, if any,...
-
On May 2, Kleinsorge Company lends $7,600 to Everhart, Inc., issuing a 6-month, 9% note. At the maturity date, November 2, Everhart indicates that it cannot pay. Instructions (a) Prepare the entry to...
-
The adjusted trial balance for Karr Bowling Alley at December 31, 2010, contains the following accounts. Instructions(a) Prepare a classified balance sheet; assume that $13,900 of the note payable...
-
An inexperienced bookkeeper prepared the following trial balance. Prepare a correct trial balance, assuming all account balances arenormal. KWUN COMPANY Trial Balance December 31, 2010 Debit Credit...
-
Explain the FAIR approach to ethical business communications.
-
Watch at least three videos of interviews with executives talking about corporate values. In four to five paragraphs, summarize what you learned. Consider the following options for gathering...
-
As a former chair of the U.S. Federal Reserve once said, Rules cannot take the place of character. In two to three paragraphs, explain what you think he meant by this statement.
Study smarter with the SolutionInn App