3
0
You have given an array from which we need to remove duplicates.
Rules:
First or immediate duplicates gets removed first.
Array contains natural numbers
a[i]>0 for i>=0
no. of elements in the array is greater than 1 i.e.
n>1
e.g.
{1,2,3,4,5,5,4,6,6,7,8}=> {1,2,3,7,8}
{1,2,3,3,4,5,6,7,7,8} => {1,2,4,5,6,8}
{1,1,3,3,4,4,6,6}=>{}
{4,2,6,8,3,1,1,3,8,6,2,4}=>{}
{6,6,6,1}=>{6,1}
Only adjacent duplicate elements like [1, 2, 2, 1]
are removed, but not [1, 2, 1, 2]
. This process is repeated until no further modifications are made.
For winning criteria is the one which gives the fastest result.
1You must specify the winning criterion clearly in your post. – Mr. Xcoder – 2017-07-15T17:53:56.397
1Should
{6,6,6,1}
output{1}
or{1,6}
? Add this on the test-case, maybe? – officialaimm – 2017-07-15T17:58:14.2701@officialaimm, It should output
{6,1}
. – Satish Patel – 2017-07-15T17:59:04.8902Why
{6,1}
?6
is a duplicate. Then,{1,2,3,4,5,5,4,6,6,7,8}
should output{1,2,3,4,5,6,7,8}
as well. – Mr. Xcoder – 2017-07-15T18:00:10.233@Mr.Xcoder, first matching duplicates gets removed. so next 6 is not having any immediate matching element so first 6's will be removed and
6,1
is remaining in the result. hope this helped – Satish Patel – 2017-07-15T18:01:50.9072@SatishPatel You should specify that in the challenge. – Mr. Xcoder – 2017-07-15T18:02:34.863
3Also, I suggest making it [tag:code-golf]. – Mr. Xcoder – 2017-07-15T18:02:55.573
1Code golf or fastest code please, not both. And if it is a code golf, please say it in your question, not with the tags. – caird coinheringaahing – 2017-07-15T18:10:31.017
@cairdcoinheringaahing, thanks for the suggestion. edited as required. – Satish Patel – 2017-07-15T18:12:04.257
1fastest-code and fastest-algorithm don't go together. – dzaima – 2017-07-15T18:35:20.783
Does the returned array need to be sorted? – powelles – 2017-07-15T18:41:40.870
@powelles
{6,1}
is not sorted... – HyperNeutrino – 2017-07-15T18:42:53.780@HyperNeutrino But it still follows the order of the original array. I guess I mean does the sort order matter at all. – powelles – 2017-07-15T18:45:10.837
@powelles Ah okay. We'll wait for OP clarification then. I don't think it matters too much since even if it increases byte count that doesn't matter, but there could be some optimizations, so I don't know for sure. – HyperNeutrino – 2017-07-15T18:47:25.177
5If you want to keep this as fastest ode (which is fine) you'll need to provide larger test cases as yours would complete almost instantaneous in any sane language and be subject to significant noise in times – Downgoat – 2017-07-15T18:48:06.763
Often problems with (simple) polynomial-time algorithm is not suitable for fastest-code. – user202729 – 2017-07-16T03:41:55.350
1
Next time, please consider using the Sandbox.
– musicman523 – 2017-07-16T04:01:44.290@musicman523, thanks for your feedback. I will make sure next time post question on sandbox first then on the main page. thanks again :) – Satish Patel – 2017-07-16T04:33:55.243