|
| 1 | +{ |
| 2 | + "problem_name": "search_in_rotated_sorted_array", |
| 3 | + "solution_class_name": "Solution", |
| 4 | + "problem_number": "33", |
| 5 | + "problem_title": "Search in Rotated Sorted Array", |
| 6 | + "difficulty": "Medium", |
| 7 | + "topics": "Array, Binary Search", |
| 8 | + "tags": ["grind-75"], |
| 9 | + "readme_description": "There is an integer array `nums` sorted in ascending order (with **distinct** values).\n\nPrior to being passed to your function, `nums` is **possibly left rotated** at an unknown index `k` (`1 <= k < nums.length`) such that the resulting array is `[nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]]` (**0-indexed**). For example, `[0,1,2,4,5,6,7]` might be left rotated by 3 indices and become `[4,5,6,7,0,1,2]`.\n\nGiven the array `nums` **after** the possible rotation and an integer `target`, return *the index of* `target` *if it is in* `nums`*, or* `-1` *if it is not in* `nums`.\n\nYou must write an algorithm with `O(log n)` runtime complexity.", |
| 10 | + "readme_examples": [ |
| 11 | + { "content": "```\nInput: nums = [4,5,6,7,0,1,2], target = 0\nOutput: 4\n```" }, |
| 12 | + { "content": "```\nInput: nums = [4,5,6,7,0,1,2], target = 3\nOutput: -1\n```" }, |
| 13 | + { "content": "```\nInput: nums = [1], target = 0\nOutput: -1\n```" } |
| 14 | + ], |
| 15 | + "readme_constraints": "- `1 <= nums.length <= 5000`\n- `-10^4 <= nums[i] <= 10^4`\n- All values of `nums` are **unique**.\n- `nums` is an ascending array that is possibly rotated.\n- `-10^4 <= target <= 10^4`", |
| 16 | + "readme_additional": "", |
| 17 | + "solution_imports": "", |
| 18 | + "solution_methods": [ |
| 19 | + { |
| 20 | + "name": "search", |
| 21 | + "parameters": "nums: list[int], target: int", |
| 22 | + "return_type": "int", |
| 23 | + "dummy_return": "-1" |
| 24 | + } |
| 25 | + ], |
| 26 | + "test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import Solution", |
| 27 | + "test_class_name": "SearchInRotatedSortedArray", |
| 28 | + "test_helper_methods": [ |
| 29 | + { "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" } |
| 30 | + ], |
| 31 | + "test_methods": [ |
| 32 | + { |
| 33 | + "name": "test_search", |
| 34 | + "parametrize": "nums, target, expected", |
| 35 | + "parametrize_typed": "nums: list[int], target: int, expected: int", |
| 36 | + "test_cases": "[([4, 5, 6, 7, 0, 1, 2], 0, 4), ([4, 5, 6, 7, 0, 1, 2], 3, -1), ([1], 0, -1), ([1], 1, 0), ([3, 1], 1, 1)]", |
| 37 | + "body": "result = self.solution.search(nums, target)\nassert result == expected" |
| 38 | + } |
| 39 | + ], |
| 40 | + "playground_imports": "from solution import Solution", |
| 41 | + "playground_test_case": "# Example test case\nnums = [4, 5, 6, 7, 0, 1, 2]\ntarget = 0\nexpected = 4", |
| 42 | + "playground_execution": "result = Solution().search(nums, target)\nresult", |
| 43 | + "playground_assertion": "assert result == expected" |
| 44 | +} |
0 commit comments