Classic Nim — Solution & Editorial
The Sprague–Grundy classic: FIRST wins iff the XOR of all pile sizes is non-zero (a non-zero XOR always has a move to zero; zero XOR must move to non-zero).
Complexity: O(N)
The Sprague–Grundy classic: FIRST wins iff the XOR of all pile sizes is non-zero (a non-zero XOR always has a move to zero; zero XOR must move to non-zero).
Complexity: O(N)