Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8971417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:56:58+00:00 2026-06-15T17:56:58+00:00

What is the best way to check if an multi-dimension array contains 2 or

  • 0

What is the best way to check if an multi-dimension array contains 2 or more equal value and only return the first one .

ex : i have an array of people that contain

[0][firstName] = 'John';
[0][lastName]  = 'Doe';

[N][firstName] = 'Marco';
[N][lastName]  = 'Polo';

[120][firstName] = 'John';
[120][lastName]  = 'Doe';

Should detect that the index 120 is a duplicate and remove it .

I’m looking for the best performance , i don’t want to loop on the array and check every time if i have the value or not .

Is there something faster ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:56:59+00:00Added an answer on June 15, 2026 at 5:56 pm

    It is the element distinctness problem which is basically O(NlogN) via sorting and iterating (after sorting, duplicates will be adjacent to each other – so easy to detect them)

    However, it can be done also in O(N) on average and with O(N) additional space by storing all elements to a hash table while iterating, and breaking if an element already exists.

    You might also want to store the original index of each element if you will later need it (and don’t use the index as key).

    pseudo code:

    map <- empty hash map
    for each element e with idx i in list (in ascending order of i):
         if (map.contains(e)):
               e is a dupe, the first element is in index map.get(e)        
         else:    
               map.add(e,i)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the best way to check if an array/tuple/list only contains elements in
What is the best way to check if the value of an input contains
what is the best way to check is a drop down contains a value
What is the best way to check if a string contains only whitespace? The
I am figuring the best way how to check if two or more url
UDPATE: SO WHATS THE BEST WAY TO ILLITERATE THROUGH A MULTI DIMENSIONAL ARRAY. SO
What is the best way to check the pointer return by a new operator
What is the best way to check that all numbers in the array (or
Possible Duplicate: Best way to check if a Data Table has a null value
What is the best way to check the text area value for line breaks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.