Hello, so I faced this problem while attempting a recruitment test on hacerrank.
From their question, it is clearly understood that they want the sum of max values of the first four columns of the iris dataset. However, my answer is marked as wrong.
Here is the code:
options(warn = -1)
df <- iris
maxFun <- function(df){
for(i in 1:nrow(df))
{
for(j in 1:(ncol(df)-1))
{
df[i,j]<-as.integer(df[i,j])
}
}
s<-0
s<-sum(max(df$Sepal.Length),max(df$Sepal.Width),max(df$Petal.Length),max(df$Petal.Width))
return(s)
}
cat(maxFun(df))
What is the problem here? and if hackerrank is expecting some other kinf of output, why are the questions not clear enough?
Aucun commentaire:
Enregistrer un commentaire