Company: Amazon_4nov
Difficulty: medium
Unpurchased Categories Problem Description A seller on the Amazon shopping platform wants to analyze purchase data of items listed in a category. There are n items on the website, indexed from 0 to n - 1 — the category of item i is given by category[i] . There is data for m customers. Each customer purchases all items between two indices (inclusive), represented by a 2D array purchase of size m × 2 , where purchase[j] = [l, r] means the j th customer bought all items from index l to r . Your task is to find all distinct item categories corresponding to items that were not purchased by any customer, sorted in ascending order. Return an array containing a single element -1 if all categories are purchased. Examples Example 1: Input: n = 5, category = [1, 2, 5, 4, 5], m = 3, purchase = [[0, 1], [0, 2], [1, 2]] Output: [4] Explanation: Given n = 5 and category = [1, 2, 5, 4, 5] . The customers make the following purchases: Customer 1 purchases items 0-1, covering categories {1, 2}. Customer