Write, efficient code for extracting unique elements from
a sorted list of array.

e.g. (1, 1, 3, 3, 3, 5, 5, 5, 9, 9, 9, 9) -> (1, 3, 5, 9).

Answer Posted / sam

private int[] GetUniqueList(int[] A)
{

if(A == null ) return null;
List<int> result = new List<int>();
for(int i=0;i<A.Length-1;i++)
{
if (A[i] != A[i + 1]) result.Add(A[i]);
}
if(A.Length>0)
result.Add(A[A.Length-1]);
return result.ToArray();
}

Is This Answer Correct ?    0 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

how to test pierrot divisor

2266


Write a routine to implement the polymarker function

4390


Sir... please give some important coding questions asked by product companies..

1805


write a c program to input initial & final time in the format hh:mm and find the time intervel between them? Ex inputs are initial 06:30 final 00:05 and 23:22 final 22.30

2228


Develop a routine to reflect an object about an arbitrarily selected plane

3004






Design an implement of the inputs functions for event mode

2970


Write a Program in 'C' To Insert a Unique Number Only. (Hint: Just Like a Primary Key Numbers In Database.) Please Some One Suggest Me a Better Solution for This question ??

1785


To Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates. String contains only lowercase characters ['a'-'z']

508


How do you verify if the two sentences/phrases input is an anagram using predefined functions in string.h and by using arrays?

2032


why nlogn is the lower limit of any sort algorithm?

2381


#include int main(void) { int a=4, b=2; a=b<>2 ; printf("%d",a); return 0; }

1082


can you use proc sql to manpulate a data set or would u prefer to use proc report ? if so why ? make up an example and explain in detail

2342


write a program for area of circumference of shapes

2040


why do you use macros? Explain a situation where you had to incorporate macros in your proc report? use a simple instream data example with code ?

2267


What is data _null_? ,Explain with code when u need to use it in data step programming ?

2830