Optimized code, still not accepting

maybe Hackerrank's problem