{"id":"4b3874a8-bbc9-4c58-a95a-80941f6251a7","name":"Largest Number","description":"You are given an array of N positive integers which represent digits of a number.\r\nYou have to form the largest number possible after performing an operation exactly once. The operation is - \r\nSelect two indices a and b, and swap their values.\r\nPrint the largest number formed.","inputFormat":"The first line contain an integer denoting number of test case T \r\nFor each testcase given an number N.\r\nNext line contains N space separated integers","outputFormat":"The output of each test case contains the largest number formed.","constraints":"1 &lt;= T &lt;= 10^3\r\n1 &lt;= N &lt;= 10^5\r\n1 &lt;= A[i] &lt;= 9","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\r\nusing namespace std;\r\nint main() {\r\n // write your code here\r\n return 0;\r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n // write your code here\r\n }\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"16\r\n41\r\n8 1 7 3 3 7 8 2 3 1 1 3 2 6 4 9 6 9 9 6 9 3 8 6 6 5 5 9 4 1 6 8 7 9 5 6 7 6 7 7 9 \r\n32\r\n1 8 8 1 7 6 2 6 3 3 9 3 7 8 9 1 5 7 8 1 4 3 7 3 1 6 4 8 4 3 1 1 \r\n21\r\n1 9 1 9 6 4 4 1 8 6 1 1 8 3 8 1 2 8 7 4 3 \r\n24\r\n7 7 6 2 3 8 9 5 7 3 1 9 8 1 2 6 6 6 6 5 6 4 1 9 \r\n44\r\n8 6 5 7 7 3 1 4 4 9 5 2 7 9 4 1 3 7 3 6 5 8 7 4 8 6 7 5 6 6 3 9 3 4 3 4 7 5 4 3 4 5 9 8 \r\n31\r\n8 5 3 1 2 7 8 5 4 8 8 6 2 8 6 1 7 4 8 4 3 4 3 7 5 7 4 1 8 6 5 \r\n37\r\n5 4 3 7 2 2 3 7 8 8 3 5 8 5 5 3 4 2 2 6 7 3 5 8 5 9 6 4 3 7 6 7 2 9 6 4 4 \r\n26\r\n4 3 4 8 7 9 8 7 9 4 1 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 5 6 5 \r\n9 4 3 7 2 2 3 7 8 8 3 5 8 5 5 3 4 2 2 6 7 3 5 8 5 9 6 4 3 7 6 7 2 5 6 4 4 \r\n9 3 4 8 7 9 8 7 9 4 1 8 9 3 1 7 1 6 7 6 8 3 1 1 4 3 \r\n9 3 7 9 9 1 8 6 3 7 7 6 1 8 2 8 4 9 6 4 6 5 3 9 1 6 4 1 7 9 6 6 2 5 6 3 8 1 \r\n9 2 5 3 1 9 8 9 5 9 9 7 1 5 4 1 6 7 5 1 3 1 3 1 3 1 2 6 7 9 3 8 5 1 1 8 3 2 6 8 2 5 6 5 7 \r\n9 5 4 5 4 6 8 4 9 3 1 9 7 9 8 6 6 8 1 8 7 4 5 7 \r\n9 9 4 1 7 1 3 9 8 2 7 3 8 3 4 4 2 7 3 6 8 1 2 7 2 2 5 1 5 2 \r\n9 6 2 9 4 2 6 8 8 2 1 6 1 3 3 8 9 9 6 9 9 2 8 3 7 2 7 9 5 2 6 3 6 9 1 8 3 9 6 7 7 4 7 7 \r\n9 9 8 2 7 7 4 6 3 3 1 1 5 7 6 4 5 5 5 7 3 6 6 1 6 \r\n9 2 6 5 9 8 8 6 1 6 8 6 6 9 2 1 5 8 1 8 7 3 3 7 4 \r\n9 7 8 6 8 8 9 3 3 4 3 3 3 1 4 4 3 4 1 5 1 1 7 6 \r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"f64cb40d-f82a-47fe-886b-f0de879e880a","name":"Largest Number","slug":"largest-number","type":1}],"next":{"id":"adfe77cc-0497-470d-9201-20d153e0c251","name":"Largest Number","type":3,"slug":"largest-number"},"prev":{"id":"c6d3ef6c-70c5-4525-af5b-f77694dff6d8","name":"First Bad Version MCQ","type":0,"slug":"first-bad-version-mcq"}}}

Largest Number

You are given an array of N positive integers which represent digits of a number. You have to form the largest number possible after performing an operation exactly once. The operation is - Select two indices a and b, and swap their values. Print the largest number formed.

{"id":"4b3874a8-bbc9-4c58-a95a-80941f6251a7","name":"Largest Number","description":"You are given an array of N positive integers which represent digits of a number.\r\nYou have to form the largest number possible after performing an operation exactly once. The operation is - \r\nSelect two indices a and b, and swap their values.\r\nPrint the largest number formed.","inputFormat":"The first line contain an integer denoting number of test case T \r\nFor each testcase given an number N.\r\nNext line contains N space separated integers","outputFormat":"The output of each test case contains the largest number formed.","constraints":"1 &lt;= T &lt;= 10^3\r\n1 &lt;= N &lt;= 10^5\r\n1 &lt;= A[i] &lt;= 9","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\r\nusing namespace std;\r\nint main() {\r\n // write your code here\r\n return 0;\r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n // write your code here\r\n }\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"16\r\n41\r\n8 1 7 3 3 7 8 2 3 1 1 3 2 6 4 9 6 9 9 6 9 3 8 6 6 5 5 9 4 1 6 8 7 9 5 6 7 6 7 7 9 \r\n32\r\n1 8 8 1 7 6 2 6 3 3 9 3 7 8 9 1 5 7 8 1 4 3 7 3 1 6 4 8 4 3 1 1 \r\n21\r\n1 9 1 9 6 4 4 1 8 6 1 1 8 3 8 1 2 8 7 4 3 \r\n24\r\n7 7 6 2 3 8 9 5 7 3 1 9 8 1 2 6 6 6 6 5 6 4 1 9 \r\n44\r\n8 6 5 7 7 3 1 4 4 9 5 2 7 9 4 1 3 7 3 6 5 8 7 4 8 6 7 5 6 6 3 9 3 4 3 4 7 5 4 3 4 5 9 8 \r\n31\r\n8 5 3 1 2 7 8 5 4 8 8 6 2 8 6 1 7 4 8 4 3 4 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 4 9 5 2 7 9 4 1 3 7 3 6 5 8 7 4 8 6 7 5 6 6 3 9 3 4 3 4 7 5 4 3 4 5 8 8 \r\n8 8 3 1 2 7 8 5 4 8 8 6 2 8 6 1 7 4 8 4 3 4 3 7 5 7 4 1 5 6 5 \r\n9 4 3 7 2 2 3 7 8 8 3 5 8 5 5 3 4 2 2 6 7 3 5 8 5 9 6 4 3 7 6 7 2 5 6 4 4 \r\n9 3 4 8 7 9 8 7 9 4 1 8 9 3 1 7 1 6 7 6 8 3 1 1 4 3 \r\n9 3 7 9 9 1 8 6 3 7 7 6 1 8 2 8 4 9 6 4 6 5 3 9 1 6 4 1 7 9 6 6 2 5 6 3 8 1 \r\n9 2 5 3 1 9 8 9 5 9 9 7 1 5 4 1 6 7 5 1 3 1 3 1 3 1 2 6 7 9 3 8 5 1 1 8 3 2 6 8 2 5 6 5 7 \r\n9 5 4 5 4 6 8 4 9 3 1 9 7 9 8 6 6 8 1 8 7 4 5 7 \r\n9 9 4 1 7 1 3 9 8 2 7 3 8 3 4 4 2 7 3 6 8 1 2 7 2 2 5 1 5 2 \r\n9 6 2 9 4 2 6 8 8 2 1 6 1 3 3 8 9 9 6 9 9 2 8 3 7 2 7 9 5 2 6 3 6 9 1 8 3 9 6 7 7 4 7 7 \r\n9 9 8 2 7 7 4 6 3 3 1 1 5 7 6 4 5 5 5 7 3 6 6 1 6 \r\n9 2 6 5 9 8 8 6 1 6 8 6 6 9 2 1 5 8 1 8 7 3 3 7 4 \r\n9 7 8 6 8 8 9 3 3 4 3 3 3 1 4 4 3 4 1 5 1 1 7 6 \r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"f64cb40d-f82a-47fe-886b-f0de879e880a","name":"Largest Number","slug":"largest-number","type":1}],"next":{"id":"adfe77cc-0497-470d-9201-20d153e0c251","name":"Largest Number","type":3,"slug":"largest-number"},"prev":{"id":"c6d3ef6c-70c5-4525-af5b-f77694dff6d8","name":"First Bad Version MCQ","type":0,"slug":"first-bad-version-mcq"}}}
plane

Editor


Loading...

Largest Number

easy

You are given an array of N positive integers which represent digits of a number. You have to form the largest number possible after performing an operation exactly once. The operation is - Select two indices a and b, and swap their values. Print the largest number formed.

Constraints

1 <= T <= 10^3 1 <= N <= 10^5 1 <= A[i] <= 9

Format

Input

The first line contain an integer denoting number of test case T For each testcase given an number N. Next line contains N space separated integers

Output

The output of each test case contains the largest number formed.

Example

Sample Input

16 41 8 1 7 3 3 7 8 2 3 1 1 3 2 6 4 9 6 9 9 6 9 3 8 6 6 5 5 9 4 1 6 8 7 9 5 6 7 6 7 7 9 32 1 8 8 1 7 6 2 6 3 3 9 3 7 8 9 1 5 7 8 1 4 3 7 3 1 6 4 8 4 3 1 1 21 1 9 1 9 6 4 4 1 8 6 1 1 8 3 8 1 2 8 7 4 3 24 7 7 6 2 3 8 9 5 7 3 1 9 8 1 2 6 6 6 6 5 6 4 1 9 44 8 6 5 7 7 3 1 4 4 9 5 2 7 9 4 1 3 7 3 6 5 8 7 4 8 6 7 5 6 6 3 9 3 4 3 4 7 5 4 3 4 5 9 8 31 8 5 3 1 2 7 8 5 4 8 8 6 2 8 6 1 7 4 8 4 3 4 3 7 5 7 4 1 8 6 5 37 5 4 3 7 2 2 3 7 8 8 3 5 8 5 5 3 4 2 2 6 7 3 5 8 5 9 6 4 3 7 6 7 2 9 6 4 4 26 4 3 4 8 7 9 8 7 9 4 1 8 9 3 1 7 1 6 7 6 8 3 1 1 9 3 38 6 3 7 9 9 1 8 6 3 7 7 6 1 8 2 8 4 9 6 4 6 5 3 9 1 6 4 1 7 9 6 9 2 5 6 3 8 1 45 1 2 5 3 1 9 8 9 5 9 9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