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

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

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

Disclosure: My content contains affiliate links.

43,237 questions

56,140 answers

573 users

How to remove duplicate maximum and minimum from unsorted array in VB.NET

1 Answer

0 votes
Imports System
Imports System.Linq

Public Class Example
    Public Shared Sub Main(ByVal args As String())
        Dim arr = {3, 5, 1, 6, 1, 1, 9, 8, 9, 9, 9, 7, 4}
        Dim max = arr.Max()
        Dim min = arr.Min()
        Dim onemin = 0 ' for fist time only: i > min (1) = no onemin++ == 0 = yes, next time onemin = 1, then 2...
        Dim onemax = 0 ' for fist time only: i > max (9) = no onemax++ == 0 = yes, next time onemax = 1, then 2...
		
        Dim result = arr.Where(Function(i) (i > min OrElse Math.Min(System.Threading.Interlocked.Increment(onemin), onemin - 1) = 0) AndAlso (i < max OrElse Math.Min(System.Threading.Interlocked.Increment(onemax), onemax - 1) = 0))
			
        Console.WriteLine(String.Join(" ", result))
    End Sub
End Class
	
	
	
	

' run:
'
' 3 5 1 6 9 8 7 4
'

 



answered Dec 13, 2022 by avibootz
...