Imports System
Public Class Test
Public Shared Sub find_first_and_Last_position(arr() As Integer, n As Integer, ByRef first As Integer, ByRef last As Integer)
first = -1
last = -1
For i As Integer = 0 to arr.Length - 1
If n <> arr(i) Then
Continue For
End If
If first = -1 Then
first = i
End If
last = i
Next
End Sub
Public Shared Sub Main()
Dim arr() As Integer = {1, 3, 7, 8, 3, 1, 9}
Dim n As Integer = 3
Dim first As Integer
Dim last As Integer
find_first_and_Last_position(arr, n, first, last)
If first <> -1 Then
Console.WriteLine("First positions = {0} Last positions = {1}", first, last)
else
Console.Write("Not Found")
End If
End Sub
End Class
' run:
'
' First positions = 1 Last positions = 4
'