---
title: "Discussion on \"Everyone uses a HashSet for LeetCode 961. I found a way to use O(1) space by hacking Moore's Voting Algorithm. Here is the math behind it.\" | Hashnode"
description: "Discussion on \"Everyone uses a HashSet for LeetCode 961. I found a way to use O(1) space by hacking Moore's Voting Algorithm. Here is the math behind it.\". LeetCode 961: N-Repeated Element in Size 2N Array is usually solved with a simple Hash Set (O(N) space) or randomized checks. But recently, I challenged myself to solve it deterministically using O(1) space.\nThe result? A modified version of Moore’s ..."
url: "https://hashnode.com/posts/everyone-uses-a-hashset-for-leetcode-961-i-found-a-way-to-use-o1-space-by-hacking-moores-voting-algorithm-here-is-the-math-behind-it/69579b40f591e14a80762e07"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Everyone uses a HashSet for LeetCode 961. I found a way to use O(1) space by hacking Moore's Voting Algorithm. Here is the math behind it.](https://pranay180825.hashnode.dev/everyone-uses-a-hashset-for-leetcode-961-i-found-a-way-to-use-o1-space-by-hacking-moores-voting-algorithm-here-is-the-math-behind-it?utm_source=hashnode&utm_medium=feed)

LeetCode 961: N-Repeated Element in Size 2N Array is usually solved with a simple Hash Set (O(N) space) or randomized checks. But recently, I challenged myself to solve it deterministically using O(1) space. The result? A modified version of Moore’s ...

Jan 2 · 3 min read · pranay180825.hashnode.dev  
Read the article

-   [#java](https://hashnode.com/tag/java)
-   [#dsa](https://hashnode.com/tag/dsa)
-   [#dsainjava](https://hashnode.com/tag/dsainjava)
-   [#moores-voting-algorithm](https://hashnode.com/tag/moores-voting-algorithm)
-   [#best-practices](https://hashnode.com/tag/best-practices)
-   [#coding](https://hashnode.com/tag/coding)
-   [#100daysofcode](https://hashnode.com/tag/100daysofcode)
-   [#buildinpublic](https://hashnode.com/tag/buildinpublic)
-   [#devcommunity](https://hashnode.com/tag/devcommunity)
-   [#faang](https://hashnode.com/tag/faang)
-   [#coding-interview](https://hashnode.com/tag/coding-interview)
-   [#software-engineering](https://hashnode.com/tag/software-engineering)
-   [#maang](https://hashnode.com/tag/maang)
-   [#algorithms](https://hashnode.com/tag/algorithms)
-   [#time-complexity](https://hashnode.com/tag/time-complexity)

## Written by

[PRANAY JAISWAL](https://hashnode.com/@pranay717)

@pranay717 · Ghaziabad,Uttar Pradesh,India

  
[View profile](https://hashnode.com/@pranay717)

Work for a Better Life | Learn. Build. Evolve.

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
