uppubhai
BAN USER
- 3of 3 votes
AnswerBob And GCD
- uppubhai in India
Bob has an array A of size N. He doesn't like arrays in which the GCD of all elements is not K. He can perform multiple operations on an array. In each operation, he can either increase or decrease the value of an element by 1.
You have to tell the minimum operation Bob will take to make GCD of all elements in an array equal to KK ?
GCD here is Greatest Common Divisor.
Input Format
The first line contains T, the number of test cases.
For Each Testcase :
The first line contains 2 integers - K and N respectively, separated by a space.
The second line contains N integers, separated by a space, in order of their position in array.
Input Constraints
1≤T≤10
1≤N≤10^6
1≤A[i]≤10^6
1≤K≤10^6
Output Format
For each test case, print minimum number of operations Bob take in a new line.
Sample Input
1
5 3
4 5 6
Ans - 2| Report Duplicate | Flag | PURGE
ThoughtWorks SDE1 - 2of 2 votes
AnswersMaximum Sum of Building Speed
- uppubhai in India
You are the king of Pensville where you have 2N workers.
All workers will be grouped in association of size 2,so a total of N associations have to be formed.
The building speed of the ith worker is Ai.
To make an association, you pick up 2N workers. Let the minimum building speed between both workers be x, then the association has the resultant building speed x.
You have to print the maximum value possible of the sum of building speeds of N associations if you make the associations optimally.
Constraints
1≤N≤5∗10 ^4
1≤Ai≤10^4
Input
First line contains an integer N, representing the number of associations to be made.
Next line contains 2N space separated integers, denoting the building speeds of 2N workers.
Output
Print the maximum value possible of the sum of building speeds of all the associations.
Sample Input
2
1 3 1 2
Sample Output
3| Report Duplicate | Flag | PURGE
Practo SDE1 Algorithm
RepYaritzaLewis, abc at 8x8
I am working as a receptionist in a Softage company. I work with the HR department to facilitate recruitment drives ...
Repmarthahiggs71, Intern at Achieve Internet
Hi, I am Martha from Toledo, OH. Working with Top NYC consulting engineers by helping them design controls projects. Have ...
Repmakaylamelua, Blockchain Developer at AMD
I am a sound editing and music composer with experience of handling a wide variety of programs.During my free ...
RepSteveParrish, Associate at ABC TECH SUPPORT
I am Steve , a Food Service Worker with a demonstrated experience in preparing various meals, maintaining kitchen equipment, cleaning the ...
RepStanPhillips, Animator at AMD
StanPhillips, a Landscape architect . I have been working at Pro Property Maintenance it's almost 10 years . I also help ...
Reppaynealiciam, Apple Phone Number available 24/7 for our Customers at Adap.tv
Hello I am Sarah Cote, and I live in Missouri, USA. Last year, Web trailblazer. Passionate entrepreneur. Subtly charming bacon ...
RepJaneBraun, Associate at ASAPInfosystemsPvtLtd
Hi, I am Jane From York,PA.My goal is to create a life that I don’t want to ...
Repemilinarula, Dev Lead at ABC TECH SUPPORT
Hi, i've been spotting for about 4 years.Teamwork: works well as a member of a team, pitches in ...
Repcarmelalewis9, Area Sales Manager at AMD
I am fond of reading stories then reading articles which are all about a story of a beautiful nature and ...
Repmarisamsan7, Cloud Support Associate at ADP
Hi, I am Photoengraver from an CO,USA. I am a girl with a strong desire to travel the world ...
Repcharlesgwitt47, Animator at ASU
By Profession, I am a Automotive service technician in Kennewick USA. My strong interest is in yoga, My yogic journey ...
Repannarrathjen, Employee at 247quickbookshelp
Hello, My name is Anna and I am a medical records technician with 2 years of experience and achievements. I ...
Repdanielhlee542, Associate at ASAPInfosystemsPvtLtd
Hi i am an health information technician at Seamans Furniture.Expertise in medical assistance, staff development and training, and implementing ...
RepAmmoBoard, Employee at A9
The best online ammo shop to buy ammunition for your rifles, handguns & shotguns from top brands you like.
RepIvyWeir, HTML Freshers at Clean Power Research
Ivy , an Empathetic and passionate Psychology student with experience in performing psychological patient assessments, assisting in psychotherapy, monitoring patients' progress ...
RepLucyKaren, Android Engineer at Abs india pvt. ltd.
I am Lucy , a Web Administrator at Oshman's Throughout my professional life, I have proved my qualities multiple times ...
Replleongardner, Animator at 247quickbookshelp
I am a writer and television producer living in the Corpus Christi area. I have always been fascinated by the ...
RepOishiGreen, Android test engineer at ABC TECH SUPPORT
I am a results-oriented debt collector with 3 years of experience and knowledge in the leasing/finance sector. I have ...
RepOllieObrien, Financial Application Engineer at Accenture
Ollie , professional writer and translator with more than 4+ years of experience. I had a passion for lifelong learning about ...
RepPeterRox, Java Developer at Cleartrip.com
I am Peter, a punctual, problem-solving, and communicative individual who possesses administration, finance, sales, computer skills and experience. I enjoy ...
RepBrezaLoni, Health inspector at Chess King
I am Health inspector from Memphis, USA .My work involves inspecting restaurants, schools, public pools, nursing homes, and daycare centres ...
RepDessieBieri, Human Resource Executive at Bazaarvoice
I am Dessie, an academic advisor with more than 2 years of extensive field experience and a well-developed industry knowledge ...
My approach which turned out to be wrong
- uppubhai December 11, 2017