Skip to content

[FEATURE REQUEST] Find Single element in an array using Bit Manipulation #5688

@Tuhinm2002

Description

@Tuhinm2002

What would you like to Propose?

An optimized way of finding single element in the array of duplicate elements (appearing twice).

  • Time complexity : O(n)
  • Space complexity : O(1)

*Test case


import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

public final class SingleElementTest {

    @Test
    void testSingleElementOne(){
        int[] arr = {1,1,2,2,4,4,3};
        assertEquals(3,SingleElement.findSingleElement(arr));
    }

    @Test
    void testSingleElementTwo(){
        int[] arr = {1,2,2,3,3};
        assertEquals(1,SingleElement.findSingleElement(arr));
    }

    @Test
    void testSingleElementThree(){
        int[] arr = {10};
        assertEquals(10,SingleElement.findSingleElement(arr));
    }
}

Issue details

The existing code base is missing this important yet easy and fun way of finding single element from an array of duplicate element using XOR operation. It takes O(n) time complexity and O(1) space complexity.

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions