How to find duplicates in an array and remove them
efficiently?

Answers were Sorted based on User's Feedback



How to find duplicates in an array and remove them efficiently?..

Answer / vishnu


Dim a(4)

a(0) = 1
a(1) = 4
a(2) = 5
a(3) = 4
a(4) = 5

For i = ubound(a)-1 to 0 step - 1
For j=0 to i
If a(j) = a(j+1) Then
a(j) = empty
ElseIf a(j)>a(j+1) Then
temp = a(j+1)
a(j+1) = a(j)
a(j) = temp
End If
Next
Next

For i=0 to ubound(a)
print a(i)
Next

Is This Answer Correct ?    1 Yes 0 No

How to find duplicates in an array and remove them efficiently?..

Answer / crazy boy

**How to find duplicates in an array and remove them efficiently?
=================================================
dim a(4)
a(0)=10
a(1)=20
a(2)=10
a(3)=20
a(4)=50

for i=0 to ubound(a)
for j=i+1 to ubound(a)
if a(i)=a(j) then
a(i) =empty
end if
next
next

for i=0 to ubound(a)
if a(i)<>"" then
msgbox a(i)
end if
next

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More QTP Interview Questions

During test run,How will you copy/paste from/to clipboard?

3 Answers  


i have an array CAPGEMINI .....Here i need to check whether G is there or not ..how to do that and friends i have one big doubt that is whether it is array or string ,how we come to know that and where we consider that it's array ,where we consider that it's an string because when i want to find the length i have big doubt whether we need to use len function or ubound ... ans me for this TWO Questions any one please

7 Answers   Cap Gemini,


plz tel me what is the differnce between QC & QTP?

3 Answers   iGate, Satyam,


what is framework and types of framework? Need of framework in automation? write folder strucuture of framework.

3 Answers   HealthAsyst,


What is checkpoints for quicktest professional (qtp)?

0 Answers  






How to insert screenshot on to the body of outlook? -1 how to use insert-picture tab in new email outlook to insert image in the body. Suggest something.......

1 Answers  


in Qtp,how to display user name and pwd (script)in data table(global sheet).

2 Answers  


what is the framework followed by ur company in qtp

5 Answers   Ordain Solutions,


what are the different Frame Works in Quick Test Proffessional testing

3 Answers   Wipro,


What is the need and applications of learning VB script for a automation(QTP) engineer ain Realtime ?

1 Answers  


Can we use smart identification in Keyword Driven approach? If yes , How we can use. Please Explain?

1 Answers  


what is the purpose of .vbs file?

2 Answers   HCL,


Categories