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

  • Home
  • SEARCH
  • 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 8387445
In Process

The Archive Base Latest Questions

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

I recently found a question that went something like: Given an array of strings,

  • 0

I recently found a question that went something like:

"Given an array of strings, return the number of distinct strings in that array."

I came up with this solution:

1. Get number_of_strings, which equals the number of strings in the input array
2. Get number_of_non_redundant, which equals the length of the input array cast as a set
3. Return 2 times number_of_non_redundant - number_of_strings

So, my question is, does this algorithm work for all data sets?

  • 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:12:48+00:00Added an answer on June 9, 2026 at 6:12 pm

    As others have pointed out, simply returning number_of_non_redundant seems like the answer to this problem.

    Here is a possible solution for determining number_of_non_redundant:

    1) Create a Hash Set (Language specific)

    2) Iterate through the entire array, on each element of the array
    check to see if the element exists in the Hash Set, if it doesn’t, add
    it.

    3) Return the size of the Hash Set.

    Using a Hash Set here offers constant time operations(add, contains).

    Additionally I wanted to point out that you can’t (at least I am not aware of this in a language) simply cast an array to a set. Casting is a constant time operation. These are two different data structures and in order to take elements from an array and place them in a set, it would require iterating through the array and entering the elements into a set.

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

Sidebar

Related Questions

I just found out recently that you can configure Visual Studio (but this question
I recently found an article online that told me about this: RewriteRule ^mock-up/([^/]+)/([^/]+) /mock-up/index.php?page=$1&section=$2
This question is based off some really odd code I recently found in a
I think this question is quite common. Recently I have got a requirement that
Recently I posted a question on Highcharts column charts drilldown. I have found that
I recently found some code like this: typedef int TenInts[10]; void foo(TenInts &arr); What
I recently found that dynamically creating object and methods in Ruby is quite a
I recently found the mobipick calendar and I really like it due to its
I recently found that one of my services was taking a large amount of
I recently found out about Cytoscape.js and would like to try out the force-directed

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.