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
1d

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...
CodeNation Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter