Imports System
Imports System.Collections.Generic
Public Class Program
Public Shared Function elements_that_appear_more_than_x_times(ByVal arr As Integer(), ByVal k As Integer) As Dictionary(Of Integer, Integer)
Dim size As Integer = arr.Length
Dim times As Integer = size / k
Console.WriteLine("more than " & times & " times")
Dim freqency_map As Dictionary(Of Integer, Integer) = New Dictionary(Of Integer, Integer)()
For i As Integer = 0 To size - 1
If freqency_map.ContainsKey(arr(i)) <> False Then
freqency_map(arr(i)) += 1
Else
freqency_map.Add(arr(i), 1)
End If
Next
Return New Dictionary(Of Integer, Integer)(freqency_map)
End Function
Public Shared Sub Main(ByVal args As String())
Dim k As Integer = 4
Dim arr As Integer() = New Integer() {4, 8, 6, 5, 5, 8, 3, 2, 1, 2, 2, 5, 5, 5, 5, 8, 9, 8, 8}
Dim freqency_map As Dictionary(Of Integer, Integer) = elements_that_appear_more_than_x_times(arr, k)
For Each item As KeyValuePair(Of Integer, Integer) In freqency_map
If item.Value > arr.Length / k Then
Console.WriteLine("{0} ", item.Key)
End If
Next
End Sub
End Class
' run:
'
' more than 5 times
' 8
' 5
'