Skip to main content

Posts

Showing posts from October, 2026

Sum of Min/Max Frequencies of the Arrays - Brute Force & Optimized Approaches

Java · DSA · Hashing ◐ Add the lowest and highest frequency in an array. Solve it two ways, brute force and hashing , then watch both run step by step on your own input. 01 Problem 02 Brute force 03 Hashing 04 Tracer 05 Comparison 06 Revision 07 Quiz 01 The problem Given an array of N non-negative integers, find how often each value occurs. Print the minimum frequency + maximum frequency . For [1, 2, 2, 3, 3, 3, 3] , the frequencies are 1 → 1, 2 → 2 and 3 → 4. The lowest is 1 and the highest is 4, so the answer is 1 + 4 = 5 . Type an array to run both programs and see every frequency. Array (spaces or commas) Run 02 Approach 1: Brute force Walk the array with i . The first time a value appears, mark it in visited and count it with an inner j loop. Then update minFreq and maxFreq with that count. Copy import java.util. Sca...