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!
Select
Add answer anonymously...

CodeNation Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. Rat in a Maze Problem Statement You need to determine all possible paths for a r...read more
A Software Developer Intern was asked Q. Kth Largest Number Problem Statement You are given a continuous stream of number...read more
A Software Developer Intern was asked Q. Count Inversions Problem Statement Given an integer array ARR of size N, your ta...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. Rat in a Maze Problem Statement You need to determine all possible paths for a r...read more
A Software Developer Intern was asked Q2. Kth Largest Number Problem Statement You are given a continuous stream of number...read more
A Software Developer Intern was asked Q3. Count Inversions Problem Statement Given an integer array ARR of size N, your ta...read more
CodeNation Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits