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)):
- sort array.
- compare adjacent elements in array
- 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)):
- create hash table value.
- insert value if not present in hash table.
- count , print values present in hashtable
Comments
Post a Comment