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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:40:13+00:00 2026-05-23T01:40:13+00:00

Input [0 1 0 0 1, 1 0 1 1 0, 0 1 0

  • 0

Input
[0 1 0 0 1,
1 0 1 1 0,
0 1 0 0 1,
1 1 1 0 0]

Expected output
[0 1 0 0 1,
1 0 1 1 0,
1 1 1 0 0]

Solution I could come up with was:

  1. For each row, convert them into decimal (or use some checksum method), takes O(n)
  2. This essentially converts the matrix into 1-dimensional array.
  3. Now use hash table, scan through all the elements
  4. Keep track of duplicates and report only unique elements from this array.

Other solutions may include using a TRIE (or a similar structure). But that would still take O(n^2)

Is there a better solution ?

  • 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-05-23T01:40:14+00:00Added an answer on May 23, 2026 at 1:40 am

    You can do it in linear time by computing a hash of each row, BucketSorting the hashes (fastest integer sort ever devised), and then removing duplicates from the sorted row (for each row, you compare the current row with the previous, and if it matches, delete the current).

    EDIT: Because everyone got downvoted, apparently by someone who doesn’t understand that iterating N items is linear regardless of how they’re arranged, I will elaborate.

    Big-O calculation does not take into account how a collection is arranged in memory, UNLESS the storage mechanism doesn’t allow for effectively constant retrieval time. Arrays, no matter how many dimensions, are considered effectively constant to retrieve from. So, we should consider going through the entire 5×5 matrix as a linear operation, because it essentially performs the same as if you’d been given a one-dimensional array of 25 objects.

    With that out of the way:

    • Hashing all elements, taken five at a time, is linear, because we need to read every element exactly once to add them to that row’s hash (which can be as simple as multiplying each element by 10^x or 2^x and adding to a running total).

    • The BucketSort algorithm executes in X*M time for a one-dimensional array of X elements with maximum order of magnitude M. As X in this case is the square root of our total N for the overall operation, and the worst-case maximum order of magnitude M would also be the square root of N, our BucketSort will execute in O(X*M) ~= O(N) worst-case.

    • Iterating through the sorted hashes is linear, on the order of the square root of our total N.

    So, the total complexity of this algorithm, executed on a matrix of N values, is roughly O(2N+sqrt(N)) which is considered O(N).

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

Sidebar

Related Questions

Input: X(P)~AK,X(MV)~AK Expected Output: P(curr=AK),MV(curr=AK) Using C#3.0 I solved by using string functions(split,then appending
Is there a better, more elegant solution to the following method? Expected input format:
Looking for something to do the following: Given input: s Expected output: t
Example Input = 1.1.0.1 Expected output = 1.101
I want to Convert my Input Xml File into more customized xml file by
How to split a string on numbers and substrings? Input: 34AG34A Expected output: {34,AG,34,A}
Input: . . . . . Expected output: . . . . .
Input : {5, 13, 6, 5, 13, 7, 8, 6, 5} Output : {5,
Input: SHC 111U,SHB 22x,, SHA 5555G Needed output: SHB 22X, SHC 111U, SHA 5555G
Input: I have a LaTeX file, with plain text & math formulas. Desired output:

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.