easyArraysPattern: Hashing

Count Unique Cargo Shipments Solution

Problem Statement

You are given a list of cargo shipment identifiers and their corresponding goods types. Determine the number of unique cargo shipments by implementing a system that efficiently handles a large number of shipments and avoids counting duplicate shipments.

Examples

Example 1:
Input:[[1, 'food'], [2, 'clothing'], [1, 'food'], [3, 'tools']]
Output:3
Explanation: Counting unique cargo shipment identifiers, which are 1, 2, and 3.
Example 2:
Input:[[4, 'furniture'], [5, 'books'], [6, 'electronics'], [4, 'furniture']]
Output:3
Explanation: Counting unique cargo shipment identifiers, which are 4, 5, and 6.

Constraints

  • The input votes list contains only positive integers.
  • There is exactly one candidate who will gain more than half of the total votes.
  • The function should return the candidate who gains more than half of the total votes.
Time: O(n) Space: O(1)
Use a set data structure to store unique identifiers with a time complexity of O(n)

Run, Test & Submit Code

Ready to practice this challenge? Launch our interactive compilation environment with compiler validation.

Solve on Interactive Workspace

Tested Solutions

No solution code is currently loaded.
Complete this code in the workspace editor.