Knowee
Questions
Features
Study Tools

Swap the contents and indexes in an array.Max. score: 100Given an array with size n and its contents are from 0 to n-1. Swap the index and contents at that index.INPUT:Accept the size and its corresponding values.OUTPUT:Print the processed array.Explaination:input:a[0] = 3 a[1] = 2 a[2] = 4 a[3] = 1 a[4] = 0output:a[0] = 4 a[1] = 3 a[2] = 1 a[3] = 0 a[4] = 2SAMPLE INPUT 54 2 0 1 3SAMPLE OUTPUT 2 3 1 4 0

Question

Swap the contents and indexes in an array.Max. score: 100Given an array with size n and its contents are from 0 to n-1. Swap the index and contents at that index.INPUT:Accept the size and its corresponding values.OUTPUT:Print the processed array.Explaination:input:a[0] = 3 a[1] = 2 a[2] = 4 a[3] = 1 a[4] = 0output:a[0] = 4 a[1] = 3 a[2] = 1 a[3] = 0 a[4] = 2SAMPLE INPUT 54 2 0 1 3SAMPLE OUTPUT 2 3 1 4 0

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

To swap the contents and indexes in an array, follow these steps:

  1. Accept the size of the array and its corresponding values as input.
  2. Create a new array of the same size to store the processed values.
  3. Iterate through each index of the input array.
  4. For each index, swap the value at that index with the value at the corresponding index in the new array.
  5. Print the processed array as the output.

Here is an example:

Input: a[0] = 3 a[1] = 2 a[2] = 4 a[3] = 1 a[4] = 0

Output: a[0] = 4 a[1] = 3 a[2] = 1 a[3] = 0 a[4] = 2

Sample Input: 5 4 2 0 1 3

Sample Output: 2 3 1 4 0

This problem has been solved

Similar Questions

You are given a 0-indexed integer array nums and an integer k. You have a starting score of 0.In one operation:choose an index i such that 0 <= i < nums.length,increase your score by nums[i], andreplace nums[i] with ceil(nums[i] / 3).Return the maximum possible score you can attain after applying exactly k operations.

Anytime MedianMax Score: 100Given an integer array, print the median for the sub-array 0 to i, for every i, 0 <= i <= N-1.Input FormatThe first line of input contains T - the number of test cases. It's followed by 2T lines - the first line contains N - the size of the array. The second line contains N integers - the elements of the array.Output FormatFor each test case, print the median for the sub-array 0 to i, for every i, separated by space. Print a new line between the output of different test cases. Note that in the case of even length sub-array, print the smaller element as the median.Constraints30 points1 <= T <= 1001 <= N <= 10370 points1 <= T <= 1001 <= N <= 104General Constraints-104 <= A[i] <= 104ExampleInput25-10 14 11 -5 7 32 -5 14 Output-10 -10 11 -5 7 2 -5 2 ExplanationSelf Explanatory

Question8Max. score: 40.00Reverse first half and second half of the array.Input format :Size of the arrayArray elementsOutput format :Reversed arrayConstraints :1<=N<=100000Sample input1 2 3 4 7 8 6 5 4Sample output4 3 2 1 7 4 5 6 8ExplanationInput :71 2 3 4 5 6 7Output :3 2 1 7 6 5 4Note:Your code must be able to print the sample output from the provided sample input. However, your code is run against multiple hidden test cases. Therefore, your code must pass these hidden test cases to solve the problem statement.LimitsTime Limit: 5.0 sec(s) for each input fileMemory Limit: 256 MBSource Limit: 1024 KBScoringScore is assigned if any testcase passesAllowed LanguagesC

You work in the examination department of a school, and you've been given a task to sort the test scores of students in ascending order. The scores are stored in a list where each element represents the score of a student.Input FormatThe first line contains the integer N, the size of the array. The next line contains N space-separated integers.Constraints• 1<=N<=1000 • -1000<=a[i]<=1000Output FormatPrint the array as a row of space-separated integers in each iteration.Sample Input 01010 9 8 7 6 5 4 3 2 1Sample Output 05 9 8 7 6 10 4 3 2 15 4 8 7 6 10 9 3 2 15 4 3 7 6 10 9 8 2 15 4 3 2 6 10 9 8 7 15 4 3 2 1 10 9 8 7 63 4 5 2 1 10 9 8 7 63 2 5 4 1 10 9 8 7 61 2 3 4 5 10 9 8 7 61 2 3 4 5 10 9 8 7 61 2 3 4 5 10 9 8 7 61 2 3 4 5 8 9 10 7 61 2 3 4 5 8 7 10 9 61 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 10

Single File Programming QuestionProblem StatementGiven an integer array sequence of size n, write a program to find the equilibrium index of the array.The equilibrium index of an array is an index such that the sum of elements at lower indexes is equal to the sum of elements at higher indexes. ExampleInput: 7-7 1 5 2 -4 3 0Output:3Explanation:3 is an equilibrium index, because, A[0] + A[1] + A[2] = A[4] + A[5] + A[6].Note: This is a question asked in Amazon and Microsoft coding tests.Input format :The first line of input consists of an integer n, representing the size of the array.The second line consists of n space-separated integers, representing the array elements.Output format :The output prints an integer representing the equilibrium index of the given array.If there is no such index found, print "No equilibrium index found."Refer to the sample output for formatting specifications.Code constraints :1 ≤ n ≤ 10-10 ≤ array elements ≤ 10Sample test cases :Input 1 :7-7 1 5 2 -4 3 0Output 1 :3Input 2 :31 2 3Output 2 :No equilibrium index found.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.