CoolFace
Datasetpublic

FPEvalDataset/LeetCodeProblem

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes305downloads
1{2    "id": 2447,3    "name": "merge_similar_items",4    "difficulty": "Easy",5    "link": "https://leetcode.com/problems/merge-similar-items/",6    "date": "1658534400000",7    "task_description": "You are given two 2D integer arrays, `items1` and `items2`, representing two sets of items. Each array `items` has the following properties: `items[i] = [valuei, weighti]` where `valuei` represents the **value** and `weighti` represents the **weight **of the `ith` item. The value of each item in `items` is **unique**. Return _a 2D integer array_ `ret` _where_ `ret[i] = [valuei, weighti]`_,_ _with_ `weighti` _being the **sum of weights** of all items with value_ `valuei`. **Note:** `ret` should be returned in **ascending** order by value. **Example 1:** ``` **Input:** items1 = [[1,1],[4,5],[3,8]], items2 = [[3,1],[1,5]] **Output:** [[1,6],[3,9],[4,5]] **Explanation:** The item with value = 1 occurs in items1 with weight = 1 and in items2 with weight = 5, total weight = 1 + 5 = 6. The item with value = 3 occurs in items1 with weight = 8 and in items2 with weight = 1, total weight = 8 + 1 = 9. The item with value = 4 occurs in items1 with weight = 5, total weight = 5. Therefore, we return [[1,6],[3,9],[4,5]]. ``` **Example 2:** ``` **Input:** items1 = [[1,1],[3,2],[2,3]], items2 = [[2,1],[3,2],[1,3]] **Output:** [[1,4],[2,4],[3,4]] **Explanation:** The item with value = 1 occurs in items1 with weight = 1 and in items2 with weight = 3, total weight = 1 + 3 = 4. The item with value = 2 occurs in items1 with weight = 3 and in items2 with weight = 1, total weight = 3 + 1 = 4. The item with value = 3 occurs in items1 with weight = 2 and in items2 with weight = 2, total weight = 2 + 2 = 4. Therefore, we return [[1,4],[2,4],[3,4]]. ``` **Example 3:** ``` **Input:** items1 = [[1,3],[2,2]], items2 = [[7,1],[2,2],[1,4]] **Output:** [[1,7],[2,4],[7,1]] **Explanation: **The item with value = 1 occurs in items1 with weight = 3 and in items2 with weight = 4, total weight = 3 + 4 = 7. The item with value = 2 occurs in items1 with weight = 2 and in items2 with weight = 2, total weight = 2 + 2 = 4. The item with value = 7 occurs in items2 with weight = 1, total weight = 1. Therefore, we return [[1,7],[2,4],[7,1]]. ``` **Constraints:** `1 <= items1.length, items2.length <= 1000` `items1[i].length == items2[i].length == 2` `1 <= valuei, weighti <= 1000` Each `valuei` in `items1` is **unique**. Each `valuei` in `items2` is **unique**.",8    "public_test_cases": [9        {10            "label": "Example 1",11            "input": "items1 = [[1,1],[4,5],[3,8]], items2 = [[3,1],[1,5]]",12            "output": "[[1,6],[3,9],[4,5]] "13        },14        {15            "label": "Example 2",16            "input": "items1 = [[1,1],[3,2],[2,3]], items2 = [[2,1],[3,2],[1,3]]",17            "output": "[[1,4],[2,4],[3,4]] "18        },19        {20            "label": "Example 3",21            "input": "items1 = [[1,3],[2,2]], items2 = [[7,1],[2,2],[1,4]]",22            "output": "[[1,7],[2,4],[7,1]] "23        }24    ],25    "private_test_cases": [],26    "haskell_template": "mergeSimilarItems :: [[Int]] -> [[Int]] -> [[Int]]\nmergeSimilarItems items1 items2 ",27    "ocaml_template": "let mergeSimilarItems (items1: int list list) (items2: int list list) : int list list =  ",28    "scala_template": "def mergeSimilarItems(items1: List[List[Int]],items2: List[List[Int]]): List[List[Int]] = { \n    \n}",29    "java_template": "public static List<List<Integer>> mergeSimilarItems(List<List<Integer>> items1, List<List<Integer>> items2) {\n\n}",30    "python_template": "class Solution(object):\n    def mergeSimilarItems(self, items1, items2):\n        \"\"\"\n        :type items1: List[List[int]]\n        :type items2: List[List[int]]\n        :rtype: List[List[int]]\n        \"\"\"\n        "31}