Hashing Theory

Hashing DSA practice problem on Onlearn.

Difficulty: medium.

Topics: Hashing: Optimized Counting and Querying of Frequencies in Arrays and Strings, Hashing, Frequency Counting, Arrays, Strings, Map, Hash Tables, Time Complexity, Space Complexity, Big O Notation, Loops, string, space complexity, mathematical operations, hashing, array, frequency counting, preprocessing, mapping, hash map, time complexity analysis, Hashing & Hash Maps, Frequency Counting, Problem Solving Techniques, Hash Functions & Collisions, Hashing with Arrays.

Element Frequency Counter Problem Statement Given a sequence of elements (either integers or characters) and a list of queries, for each query, determine how many times the queried element appears in the original sequence. Input Specification The input will consist of multiple test cases or sections, each demonstrating frequency counting for a specific data type. Section 1: Integer Frequency Counting Line 1: An integer N (1 <= N <= 10^5), representing the number of elements in the sequence. Line 2: N space separated integers arr[i] (0 <= arr[i] <= 10^9), representing the elements of the sequence. Line 3: An integer Q (1 <= Q <= 10^5), representing the number of queries. Line 4: Q space separated integers query val[j] (0 <= query val[j] <= 10^9), representing the elements to query. Section 2: Character Frequency Counting Line 1: A string S (1 <= |S| <= 10^5), consisting of lowercase English letters. Line 2: An integer Q (1 <= Q <= 10^5), representing the number of queries. Line 3: Q space separated characters query char[j], representing the characters to query. Output Specification For each query in each section, print the frequency of the queried element on a new line. Constraints Time Limit: 1 second Memory Limit: 256 MB Sample Test Cases Sample 1: Integer Frequency Counting Input: Output: Sample 2: Integer Frequency Counting (Large Values Map Example) Input: Output: Sample 3: Character Frequency Counting (Lowercase Letters) Input: Output: