Polycarp has an array of n (n is even) integers a1,a2,…,an. Polycarp conceived of a positive integer k. After that, Polycarp began performing the following operations on the array: take an index i (1≤i≤n) and reduce the number ai by k. After Polycarp performed some (possibly zero) number of such operations, it turned out that at least half of the numbers in the array became the same. Find the

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Help in this for code. Correct answer will upvoted else downvoted.

 

Polycarp has an array of n (n is even) integers a1,a2,…,an. Polycarp conceived of a positive integer k. After that, Polycarp began performing the following operations on the array: take an index i (1≤i≤n) and reduce the number ai by k.

After Polycarp performed some (possibly zero) number of such operations, it turned out that at least half of the numbers in the array became the same. Find the maximum k at which such a situation is possible, or print −1 if such a number can be arbitrarily large.

Input: The first line contains one integer t (1≤t≤10) — the number of test cases. Then t test cases follow.Each test case consists of two lines. The first line contains an even integer n (4≤n≤40) (n is even). The second line contains n integers a1,a2,…an (−106≤ai≤106).It is guaranteed that the sum of all n specified in the given test cases does not exceed 100.

Output: For each test case output on a separate line an integer k (k≥1) — the maximum possible number that Polycarp used in operations on the array, or −1, if such a number can be arbitrarily large.

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education