You are not logged in. Please login at www.codechef.com to post your questions!

×

Unique elements in 2D vector

How can i find Set of Unique Elements In 2d Vector in most EFFICIENT WAY??

Vector Declaration :

    vector <int> par[100000];

Example :

Input :

1,2,3,4

1,4,3,2

1,2,3,4

5,4,2,9

8,6,5,4

1,2,3,4

Output :

1,2,3,4

1,4,3,2

5,4,2,9

8,6,5,4

asked 10 Aug, 14:40

chunky_2808's gravatar image

4★chunky_2808
996
accept rate: 5%


You can make trie type structure or you can also use unordered map..

For trie type structure, at each level you would store a column in sorted manner and insert and find element accordingly.. This link may help.

               1                            5                          8
        2             4                     4                          6
        3             3                     2                          5
        4             2                     9                          4

This is how your trie will look like.. Hope this will help..

link

answered 10 Aug, 15:57

kauts_kanu's gravatar image

5★kauts_kanu
1.0k19
accept rate: 19%

edited 10 Aug, 16:40

1

Hey Thanks for it @kauts_kanu. :)

(10 Aug, 16:19) vishesh_3454★

Thanks!!!!

(10 Aug, 18:55) chunky_28084★

Do you want to perform some operations on the resultant 2D matrix? How about inserting them in a set of vectors. I guess you want a more efficient way compared to NlogN.(N is the unique number of elements in set). Still thinking an efficient way.:)

link

answered 10 Aug, 15:03

vishesh_345's gravatar image

4★vishesh_345
2267
accept rate: 7%

edited 10 Aug, 15:05

Thanks!! Learned something new!!

(10 Aug, 18:56) chunky_28084★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×67
×11

question asked: 10 Aug, 14:40

question was seen: 205 times

last updated: 10 Aug, 18:56