Key-Value Maps
Data Structures & Libraries DSA practice problem on Onlearn.
Difficulty: medium.
Topics: What is C++ STL (Standard Template Library) and what are its primary components and usage in programming?, Standard Template Library (STL), Data Structures, Map, Time Complexity, Space Complexity, Big O Notation, general programming, algorithms, C++ Language Fundamentals, Standard Template Library (STL), Templates, Containers, Algorithmic Paradigms, Iterators, Functions.
Warehouse Inventory Management Problem Statement You are tasked with managing the inventory of a warehouse. You will receive a series of item IDs. For each item ID received, you need to update your inventory. After processing all item IDs, you need to provide two pieces of information: 1. The total number of distinct item IDs in the inventory. 2. A list of all unique item IDs, sorted in ascending order, along with their respective counts. Input Specification The first line contains an integer N (1 <= N <= 10^5), the number of item IDs. The second line contains N integers item id 1, item id 2, ..., item id N (1 <= item id i <= 10^9), representing the item IDs received. Output Specification First line: The total number of distinct item IDs. Subsequent lines: Each line should contain a unique item ID followed by its count, separated by a space. These lines should be sorted by item ID in ascending order. Sample Test Cases Sample Input 1 Sample Output 1