Array-7 Assemble Minions
Array-7 Assemble Minions
Assignment Questions
Question Name: Assemble the minions
Problem Statement
Gru, the criminal mastermind wants to rob the Deshute Bank. To do that he hired N minions. The minions
randomly arranged themselves in front of the main gate of the bank but Gru wants all of them to be
assembled together. More precisely consider that the minions are arranged in the x-axis with each minion
initially standing at position Pi. Gru wants each of the minions to come at the same position.
But Gru is running out of time as the local police will arrive in few minutes. So he does not have the time
to go to each minion and say them to assemble together. So he decided to give a loudspeaker to one of
the minions who will make the announcement. But the loudspeaker has a maximum range of K so after
the announcement only those minions who are at a distance less than K from this minion will come to him.
Given the initial positions of the minions, you have to tell whether it is possible to assemble all the minions
or not.
Input Forma
First line contains T denoting the number of testcases
First line of every test case contains two space separated integers N and K denoting the number of
minions and maximum range of the loudspeaker respectively
Next line contains N space separated integers denoting the initial positions of the minions.
Output Forma
Print “YES” if it is possible to assemble all the minions else print “NO”
Constraint
1<=T<=
2<=N<=10
0<=K<=10
1<=Initial position of minions<=109
Sample Input 1
5 2
1 2 3 4 5
5 1
1 2 3 4 5
Sample Output 1
YES
NO
Assignment Questions
Explanation of Sample 1
Array
Assemble the Minions
Practice Problems
Assignment Solutions
Assignment Solutions
process.stdin.resume();
process.stdin.setEncoding('utf8');
let currentLine = 0;
inputString += inputStdin;
});
inputString = inputString
.trim()
.split("\n")
.map((string) => {
return string.trim();
});
main();
});
function readLine() {
return inputString[currentLine++];
function input() {
let n, k;
.split(" ")
n = input_arr2[0];
k = input_arr2[1];
return solve(n,k)
function solve(n,k) {
.split(" ")
Assignment Solutions
var is = 1;
if (is) return 1;
return 0;
/////////////
function main() {
let t = parseInt(readLine());
while (t--) {
if (input()) {
console.log("YES");
} else {
console.log("NO");
Assembletheminions.js