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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:28:21+00:00 2026-06-09T18:28:21+00:00

I am trying to solve this, but i don’t know how… Values[10] = {1,1,4,4,2,3,3,2,1,3}

  • 0

I am trying to solve this, but i don’t know how…

Values[10] = {1,1,4,4,2,3,3,2,1,3}

to print:

{1,2,3,4} or {1,4,2,3} (not sorted, any order, but distinct)

I also need to count the number of times each number has occurred, both without sort, new arrays or boolean methods or other data structures, please advise as i am stuck.

Is there a simple method i can use to just print the unique values/ distinct values ?

  • 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-09T18:28:22+00:00Added an answer on June 9, 2026 at 6:28 pm

    It can be accomplished if your are willing to destroy your current array. and you assume that the array is either of type Integer (so nullable) or if not there is some bound such as all int are poistive so you can use -1.

    for(int i = 0;  i < values.length; i++){               //for entire array             
    
        Integer currVal = values[i];                       // select current value
        int count = 1;                                     // and set count to 1
    
        if(currVal != null){                               // if value not seen
    
            for( int j = i + 1; j < values.length; j++){   // for rest of array
                if(values[j] == currVal){                  // if same as current Value 
                    values[j] = null;                      // mark as seen
                    count++;                               // and count it 
                } 
            }
            System.out.print("Number : "  + currVal + "  Count : " + count + "\n");
                                                           //print information
        }
                                                           // if seen skip.
    }
    

    In plain english, Go through the array in 2 loops, roughly O(n^2) time.
    Go to index i. If index has not yet been seen (is not null) then go through the rest of array, mark any indexs with same value as seen (make it null) and increment count varable. At end of loop print value and count. If Index has be seen (is null) skip and go to next index. At end of both loops all values will be left null.

    Input : Values[] = {1,1,4,4,2,3,3,2,1,3}
    
    
    Output : Values[] = {1,null,4,null,2,3,null,null,null,null}
              Number : 1 Count : 3
              Number : 4 Count : 2
              Number : 2 Count : 2
              Number : 3 Count : 3
    

    Edit: corrected my mistake in output, pointed out by commenters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to solve this issue recently, but i don't really know how.
I was trying many many time to solve this conflict. But I don't know
I don't understand anything about IIS, but am trying to solve this problem of
Have spent an hour trying to solve this - but to no avail. I'm
I've been trying to solve this problem for a number of days now but
I have been trying to solve this problem for a while, but couldn't with
I could solve this using loops, but I am trying think in vectors so
I was trying to solve this problem in UVa, but I get a NullPointerException
I am trying to solve a problem in Objective-C, but I don't think the
I am trying to solve this error, but failed miserably. I have declared my

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.