Back

Codekata array3- Array beautiful or not

Created 10 mons ago
36 Views
1 Comments
mohand0wiIv
@mohand0wiIv
mohand0wiIv
@mohand0wiIvProfile is locked. Login

kindly validate the output :

--> test case failed. why expected 0 where array met the condition(divisible by 5)

3) You are given with array of numbers. you have to find whether array is beautiful or not. A beautiful array is an array whose sum of all numbers is divisible by 2, 3 and 5

Input Description:
You are given a number ‘n’ denoting the size of array. Next line contains n space separated numbers.

Output Description:
Print 1 if array is beautiful and 0 if it is not

const readline = require("readline");

const inp = readline.createInterface({
  input: process.stdin
});

const userInput = [];

inp.on("line", (data) => {
  userInput.push(data);
});

inp.on("close", () => {
  //start-here
  //Your code goes here … replace the below line with your code logic 
  
  const arr = userInput[1].split(" ").map(x=>+x)
 
 //console.log(arr)
 let count=0;
 
 for(let i=0; i<arr.length;i++){
      
      
     count=count+arr[i];
      
 }
 //console.log(count)
  let flag;
  if(count%2===0){
      flag=1;
      
  }
  else if(count%3===0){
      flag=1;
      
  }
  else if(count%5===0){
      flag=1;
      
  }
  else{
      flag=0;
  }
 
console.log(flag);
 

  //end-here
});
Test case failed:

>>> error
Input:
7
15 15 15 15 15 15 15
Expected Output:
0
Actual Output:
1
Comments
Please login to comment.