Kotlin. Beats 100% (146 ms). Hex number comparison.
\n\n# Code\n\nclass Solution {\n    fun countSeniors(details: Array<String>): Int {\n        return details.count {\n            (it[11] - \'0\') shl 4 or (it[1
![image.png](https://assets.leetcode.com/users/images/5ec0538a-9fe9-43f2-b36b-d65b8d99cd0b_1722499257.7180567.png)\n\n# Code\n```\nclass Solution {\n    fun countSeniors(details: Array<String>): Int {\n        return details.count {\n            (it[11] - \'0\') shl 4 or (it[12] - \'0\') > 0x60\n        }\n    }\n}\n```\n\n# Approach \n\nLet\'s try to number all the characters in the passenger line:\n\n```\n//       012345678901234\nval s = "7868190130M7522"\n```\n\nAs we can see, gender is the 10th character of the string, and the 11th and 12th characters form the age:\n\n```\n//         012\nval s = "..M75.."\n```\n\nThese symbols with numbers are in the ASCII encoding. It means, symbols \'0\'..\'9\' are encoded with values \u200B\u200Bfrom 48 (0x30) to 59 (0x39) inclusive.\n\nTo convert a single character of a string to a number, we can perform a simple operation of subtracting the value \'0\' (or 0x30) from the character, for example:\n\n```\nval s = "7868190130M7522"\nval firstDigit: Int = s[11] - \'0\' // firstDigit = 7\nval secondDigit: Int = s[12] - \'0\' // secondDigit = 5\n```\n\nSo to convert 2 digit characters into a number we could use the following algorithm:\n\n```\nval s = "7868190130M7522"\nval age = (s[11] - \'0\') * 10 + (s[12] - \'0\') // age = 75\n```\n\nBut! There is a very important "but" here - the multiplication operation is a SLOW OPERATION for the CPU. I don\'t like multiplications )\n\nInstead of multiplying by 10, we can multiply the number by 16. But not with multiplication, but with a bitwise shift to the left. This will be faster. And we can add the second digit to the result, but add it using a bitwise "OR". This will also be faster:\n\n```\nval s = "7868190130M7522"\nval age = (s[11] - \'0\') shl 4 or (s[12] - \'0\') // age = 0x75 (age = 117)\n```\n\nWith this conversion we get the age as a byte, where the high four bits will be the upper digit of the age, and the low four bits will be the lower digit of the age.\n\nIt is easy to see that in our case the string will match the "senior passenger" condition if both quadruples of bits form a value greater than 0x60:\n\n```\nclass Solution {\n    fun countSeniors(details: Array<String>): Int {\n        return details.count {\n            ((it[11] - \'0\') shl 4 or (it[12] - \'0\')) > 0x60\n        }\n    }\n}\n```
['Kotlin']