JS 50ms faster than 100%
\n\n# Code\n\n/**\n * @param {number[]} students\n * @param {number[]} sandwiches\n * @return {number}\n */\nvar countStudents = function(students, sandwiches) 
![image.png](https://assets.leetcode.com/users/images/8e8f7ced-30b5-46b1-8952-c0eeed2d49ff_1668501271.4312322.png)\n\n# Code\n```\n/**\n * @param {number[]} students\n * @param {number[]} sandwiches\n * @return {number}\n */\nvar countStudents = function(students, sandwiches) {\n    for (let i = 0 ; i < sandwiches.length; i++) {\n        const sandwich = sandwiches[i];\n        let check = false;\n        let length = students.length;\n        \n        for (let j = 0; j < length; j++) {\n            const student = students[j];\n            if (student === sandwich) {\n                check = true;\n                students.splice(j, 1);\n                break;\n            } else {\n                students.push(students.shift());\n                j--;\n                length--;\n            }\n        }\n\n        if (!check) return students.length;\n    }\n\n    return students.length;\n};\n```
['JavaScript']