CoolFace
Datasetpublic

FPEvalDataset/LeetCodeProblem

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes304downloads
1{2    "id": 2323,3    "name": "minimum_bit_flips_to_convert_number",4    "difficulty": "Easy",5    "link": "https://leetcode.com/problems/minimum-bit-flips-to-convert-number/",6    "date": "1647648000000",7    "task_description": "A **bit flip** of a number `x` is choosing a bit in the binary representation of `x` and **flipping** it from either `0` to `1` or `1` to `0`. For example, for `x = 7`, the binary representation is `111` and we may choose any bit (including any leading zeros not shown) and flip it. We can flip the first bit from the right to get `110`, flip the second bit from the right to get `101`, flip the fifth bit from the right (a leading zero) to get `10111`, etc. Given two integers `start` and `goal`, return_ the **minimum** number of **bit flips** to convert _`start`_ to _`goal`. **Example 1:** ``` **Input:** start = 10, goal = 7 **Output:** 3 **Explanation:** The binary representation of 10 and 7 are 1010 and 0111 respectively. We can convert 10 to 7 in 3 steps: - Flip the first bit from the right: 1010 -> 1011. - Flip the third bit from the right: 1011 -> 1111. - Flip the fourth bit from the right: 1111 -> 0111. It can be shown we cannot convert 10 to 7 in less than 3 steps. Hence, we return 3. ``` **Example 2:** ``` **Input:** start = 3, goal = 4 **Output:** 3 **Explanation:** The binary representation of 3 and 4 are 011 and 100 respectively. We can convert 3 to 4 in 3 steps: - Flip the first bit from the right: 011 -> 010. - Flip the second bit from the right: 010 -> 000. - Flip the third bit from the right: 000 -> 100. It can be shown we cannot convert 3 to 4 in less than 3 steps. Hence, we return 3. ``` **Constraints:** `0 <= start, goal <= 109` **Note:** This question is the same as 461: Hamming Distance.",8    "public_test_cases": [9        {10            "label": "Example 1",11            "input": "start = 10, goal = 7",12            "output": "3 "13        },14        {15            "label": "Example 2",16            "input": "start = 3, goal = 4",17            "output": "3 "18        }19    ],20    "private_test_cases": [21        {22            "input": [23                464185174,24                94272621925            ],26            "output": 1627        },28        {29            "input": [30                592770047,31                5649557732            ],33            "output": 1334        },35        {36            "input": [37                485221247,38                21586654239            ],40            "output": 1541        },42        {43            "input": [44                269177716,45                25550589346            ],47            "output": 1648        },49        {50            "input": [51                196878261,52                17554311053            ],54            "output": 1455        },56        {57            "input": [58                531827332,59                69974065260            ],61            "output": 1462        },63        {64            "input": [65                137185274,66                61027776067            ],68            "output": 1769        },70        {71            "input": [72                667761609,73                63694333874            ],75            "output": 1176        },77        {78            "input": [79                853433529,80                51694752181            ],82            "output": 1383        },84        {85            "input": [86                208171254,87                5795822288            ],89            "output": 1690        }91    ],92    "haskell_template": "minBitFlips :: Int -> Int -> Int\nminBitFlips start goal ",93    "ocaml_template": "let minBitFlips (start: int) (goal: int) : int =  ",94    "scala_template": "def minBitFlips(start: Int,goal: Int): Int = { \n    \n}",95    "java_template": "public static int minBitFlips(int start, int goal) {\n\n}",96    "python_template": "class Solution(object):\n    def minBitFlips(self, start, goal):\n        \"\"\"\n        :type start: int\n        :type goal: int\n        :rtype: int\n        \"\"\"\n        "97}