You are viewing a single comment's thread. Return to all comments →
No i agree with you that it should check the even condition but
i dont know what is wrong with the hackerank testing arlgorithm that it is only considering number between 6 to 20(irrespective of even or odd).Go ahead submit the code without n%2==0 condition it does follow all test cases correctly.Thats why i said code is not asking you to check even condition.
Well even I added n%2==0 condition but we do not need to.
As it has been said that if n is odd it is weird and if even numbers between 6-20 are weird then it doesnt matter that the number is even or odd in 6-20 as odd numbers are already weird with the condition n%2==1.
So we can have if(n%2==1 || (n>=6 && n<=20)) for the weird condition.