c - Array in JAVA., repeat? -


i'm writing function using java language takes in 1d array , size of array inputs function. want find out how many function values of in array. how this?

approach 1(o(nlogn)):

  1. sort array.
  2. compare adjacent elements in array
  3. increment count whenever adjacent elements unequal. please take care of 3 consecutive same elements using variable.

approach 2(o(n) space complexity of o(n)):

  1. create hash table value.
  2. insert value if not present in hash table.
  3. count , print values present in hashtable

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -