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 8646937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:56:23+00:00 2026-06-12T12:56:23+00:00

I am using first array to store all database of numbers where some numbers

  • 0

I am using first array to store all database of numbers where some numbers are duplicates.

I have went through this array to see which items are duplicated and am adding index of duplicated items to second array.

Now, I must loop through first array and add all but duplicated values to third array (assuming that we know which fields are duplicated).

But how to do this correctly? I can’t make it stop adding every item from first array to third array.

Assuming I can’t use HashSet().

The purpose of this is to demonstrate how to move one array to other with removed duplicated in O(N) time complexity.

Input numbers: 00, 11, 11, 22, 33, 44, 55, 55, 66, 77, 88, 99
Output which index are duplicated: 1, 2, 6, 7
Output I get: 00, 11, 11, 22, 33, 44, 55, 55, 66, 77, 88, 99 (same as the input)

Code:

   public void dups() 
   {
       int[] b = new int[100];
       int[] c = new int[100];

       int k = 0;
       int n = 0;
       int p = 0;

       for (int i = 0; i < nElems; i++)
           for (int j = 0; j < nElems; j++)
               if(a[j].equals(a[i]) && j != i)
                   b[k++] = i;

       for (int l = 0; l < k; l++)
           System.out.print(b[l] + " ");

       for (int m = 0; m < nElems; m++)
           if (m != b[p + 2])
               c[m] = (Integer) a[n++];

       System.out.print("\n");

       for (int o = 0; o < nElems; o++)
           System.out.print(c[o] + " ");
   }
  • 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-12T12:56:24+00:00Added an answer on June 12, 2026 at 12:56 pm

    Instead of marking all duplicates you could mark all that have already been seen earlier.

    Instead of:

    for (int i = 0; i < nElems; i++)
      for (int j = 0; j < nElems; j++)
        if(a[j].equals(a[i]) && j != i)
          b[k++] = i;
    

    Use something like:

    for (int i = 0; i < nElems; i++)
      for (int j = i+1; j < nElems; j++)
        if(a[j].equals(a[i]))
          b[k++] = j;
    

    You should then see:

    Output which index are duplicated: 2, 7
    

    Which should be much easier to work with.

    Here’s a working solution – although I wouldn’t do it this way:

    public class Test {
      Integer[] a = {00, 11, 11, 22, 33, 44, 55, 55, 66, 77, 88, 99};
      int nElems = a.length;
    
      public void dups() {
        int[] b = new int[100];
        int[] c = new int[100];
    
        int k = 0;
        int n = 0;
        int p = 0;
    
        for (int i = 0; i < nElems; i++) {
          for (int j = i + 1; j < nElems; j++) {
            if (a[j].equals(a[i])) {
              b[k++] = j;
            }
          }
        }
    
        for (int l = 0; l < k; l++) {
          System.out.print(b[l] + " ");
        }
        for (int m = 0; m < nElems; m++) {
          if (m != b[p]) {
            c[n++] = a[m];
          } else {
            p += 1;
          }
        }
    
        System.out.print("\n");
    
        for (int o = 0; o < nElems - k; o++) {
          System.out.print(c[o] + " ");
        }
      }
    
      public static void main(String args[]) {
        new Test().dups();
      }
    }
    

    which prints:

    2 7 
    0 11 22 33 44 55 66 77 88 99
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first time using SQL at all, so this might sound basic.
I'm using PostgreSQL 9.1.13 Here is what I've done so far: /* First Array
I am sorting and sectioning a tableview using the first letter of an array
Is there anyways to get first two element of each profile_id using php array(
I'm using Code First with EF 5. Currently I have SPs that return just
I've been using Database First, EF 4.1 I am getting The entity type List`1
I'm using the first answer to this question Overcoming Python's limitations regarding instance methods
Easier to show by example -- I'm using code-first to construct a database. I
I have a database that a time filed that is stored in this format
to all. i developing a webpage using asp.net with c# language, in this webpage

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.