
Asked in CodeNation
Array Transformation Problem
Given an array ARR
consisting of N
integers and a non-negative integer K
. An operation on the array replaces each element ELE
with MX - ELE
, where MX
is the maximum element of the array. Perform this operation exactly K
times and return the updated array.
Input:
A single integer 'T' indicating the number of test cases. For each test case, the first line contains two integers 'N' and 'K'. The second line contains 'N' space-separated integers representing the array elements.
Output:
For each test case, print the transformed array elements as single space-separated integers after 'K' operations.
Example:
Input:
2
3 1
1 2 3
4 2
5 7 2 -1
Output:
2 1 0
3 1 6 9
Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 104
-109 ≤ ARR[i] ≤ 109
0 ≤ K ≤ 109
Note:
The array is zero-indexed, and subsequent operations are performed on the updated array obtained from the previous operation.

AnswerBot
4mo
Given an array and a non-negative integer K, perform K operations on the array by replacing each element with MX - element, where MX is the maximum element of the array.
Find the maximum element in the...read more
Help your peers!
Add answer anonymously...
Top Software Developer Intern Interview Questions Asked at CodeNation
Q. Rat in a Maze Problem Statement You need to determine all possible paths for a r...read more
Q. Count Distinct Bitwise OR of All Subarrays Given an array of positive integers, ...read more
Q. Graph Coloring Problem You are given a graph with 'N' vertices numbered from '1'...read more
Interview Questions Asked to Software Developer Intern at Other Companies
Top Skill-Based Questions for CodeNation Software Developer Intern
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
C++ Interview Questions and Answers
150 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

