When any node creates a sequential ephemeral node under /election to try to assume leadership, Zookeeper automatically assigns sequence number for the sequential ephemeral node. How does a server know it can assume leadership? It can issues getChildren to acquire the child nodes of /election and determines if the znode it just created has the smallest sequence number. If yes, then it may assume leader responsibility. If not, then it sets a watch for the znode that has the largest sequence number that's smaller than the sequence number of its znode.
For example, three servers A, B and C try to acquire leadership by creating an ephemeral znode guid-n_X, where X is the sequence number Zookeeper assigns. Let's say B makes it first and creates a znode /election/guid-n_0, followed by C (/election/guid-n_1) and A (/election/guid-n_2). Server B knows it has the znode that has the smallest sequence number after it successfully created it and calls getChildren to get the list of child nodes. The other two servers also perform the same procedure to know that they are not the leaders. They, however, set only one watch on the previous znode so it prevents herding effect and they can also know when the old leader is dead and they should assume leadership. So in this case server C sets a watch on /election/guid-n_0 and Server A sets a watch on /election/guid-n_1. When B is dead, it stops sending heartbeats to Zookeeper and its ephemeral znode gets deleted. Server C then gets notified of this event and it can act as the new leader.
Hope this answers your question.