Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,926 questions

51,859 answers

573 users

How to find missing elements of a given range in array of distinct elements with VB.NET

1 Answer

0 votes
Imports System
Imports System.Collections.Generic

Public Class Program
    Public Shared Sub printMissingElements(ByVal arr As Integer(), ByVal range_start As Integer, ByVal range_end As Integer)
        Dim hset As HashSet(Of Integer) = New HashSet(Of Integer)()

        For i As Integer = 0 To arr.Length - 1
            hset.Add(arr(i))
        Next

        For i As Integer = range_start To range_end
            If Not hset.Contains(i) Then
                Console.Write(i & " ")
            End If
        Next
    End Sub

    Public Shared Sub Main(ByVal args As String())
        Dim arr As Integer() = New Integer() {2, 4, 5, 7, 9}
        Dim range_start As Integer = 1, range_end As Integer = 9

        printMissingElements(arr, range_start, range_end)
    End Sub
End Class




' run:
'
' 1 3 6 8
'

 



answered May 23, 2023 by avibootz
...