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,880 questions

51,806 answers

573 users

How to get the minimum elements to be deleted to make an array with same values in VB.NET

1 Answer

0 votes
Imports System
Imports System.Collections.Generic

Public Class Example
    Public Shared Function minElementsToBeDelete(ByVal arr As Integer()) As Integer
        Dim frequency As Dictionary(Of Integer, Integer) = New Dictionary(Of Integer, Integer)()
        Dim size As Integer = arr.Length

        For i As Integer = 0 To size - 1
            If frequency.ContainsKey(arr(i)) Then
                frequency(arr(i)) = frequency(arr(i)) + 1
            Else
                frequency(arr(i)) = 1
            End If
        Next

        Dim max_frequency As Integer = Integer.MinValue
        For Each i As Integer In frequency.Keys
            max_frequency = Math.Max(max_frequency, frequency(i))
        Next

        Return size - max_frequency
    End Function

    Public Shared Sub Main(ByVal args As String())
        Dim arr As Integer() = New Integer() {3, 5, 3, 8, 3, 3, 9, 3, 2, 2}

        Console.WriteLine(minElementsToBeDelete(arr))
    End Sub
End Class






' run
'
' 5
'

 



answered Dec 12, 2022 by avibootz
...