BEATS 100% RUNTIME !!! NO STACK ❌ NO QUEUE ❌ ONLY ARRAY LOGIC ✅ !!! FULL EASY EXPLANATION 👌
SCREENSHOT :)\n\n\n\n\n# Intuition\nThe intuition behind this approach is to simulate the process of distributing sandwiches to students. It iterates over both 
**SCREENSHOT :)**\n\n![leet.png](https://assets.leetcode.com/users/images/c54301c3-876d-4470-97eb-f0653b532111_1712557175.5454159.png)\n\n\n# *Intuition*\n**The intuition behind this approach is to simulate the process of distributing sandwiches to students. It iterates over both the students and sandwiches arrays, matching preferences and marking served students. By keeping track of the count and using a flag to detect when a full iteration over students is made without any changes, it ensures termination of the loop. Finally, it counts the remaining students who have not received sandwiches.**\n\n\n![7abc56.jpg](https://assets.leetcode.com/users/images/68a5528e-fb0a-4925-b2b2-de842b6ec7a7_1712557230.4337175.jpeg)\n\n\n\n\n\n\n\n# ***Initialization:***\n\n**st stores the total number of students, and count keeps track of the number of students who have received sandwiches.\ni is the index used for iterating through the students array.\nflag is a flag variable to indicate whether a full iteration over the students has been made without any changes. This is used to break out of an infinite loop.**\n\n# *Main Loop:*\n\n**The loop iterates indefinitely (while(1)) until all students have received their sandwiches OR the other condition.\nIt checks if the current student\'s preference matches the sandwich available (students[i] == sandwiches[count]).\nIf a match is found, it increments count to indicate that one more student has received a sandwich, marks the student\'s preference as served (assigns students[i] = 2), and resets the flag to 1.\nIf all students have received sandwiches (count == st), the loop breaks.\nAfter each iteration, i is incremented. If i reaches the total number of students (st), it resets to 0.\nIf the loop completes a full iteration without any changes (flag == 0), it breaks out of the loop.**\n\n# *Counting Remaining Students:*\n\n**After the main loop, it counts the number of students who have not received sandwiches by iterating over the students array.\nAny student whose preference is not marked as served (not equal to 2) contributes to the count.**\n\n# *Return:*\n\n**The function returns the count of students who have not received sandwiches.**\n\n# Complexity\n- **Time complexity**: $$O(n^2)$$ \n\n- **Space complexity**: $$O(1)$$\n\n\n# Code\n```\nint countStudents(int* students, int studentsSize, int* sandwiches, int sandwichesSize) {\n    int st = studentsSize;\n    int count = 0;\n    int i = 0;\n    int flag = 0;\n    while(1) {\n        if(students[i] == sandwiches[count]) {\n            count++;\n            students[i] = 2;\n            flag = 1;\n            if(count == st) {\n                break;\n            }\n        }\n        i++;\n        if(i == st && flag == 1) {\n            i = 0;\n            flag = 0;\n            continue;\n        }\n        else if(i == st && flag == 0) {\n            break;\n        }\n    }\n    count = 0;\n    for(int i = 0 ; i < st ; i++) {\n        if(students[i] != 2) {\n            count++;\n        }\n    }\n    return count;   \n}\n```\n\n\n
['C']