Solved Binary Search Set 1#2489
Conversation
Search inside a Rotated Sorted Array (Problem_1.py)Your solution for searching in a 2D matrix is well-written and efficient for that problem. However, the problem you were asked to solve is about searching in a rotated sorted array, not a 2D matrix. It seems there might have been a misunderstanding of the problem statement. For the rotated sorted array problem, you need to implement a binary search that accounts for the rotation. The key idea is to determine which half of the array is sorted and then check if the target lies within that sorted half. Here's a brief outline of the correct approach:
Your current code does not address this logic at all. I recommend revisiting the problem statement and implementing the solution for the rotated sorted array. Also, ensure that your function name and parameters match the requirements (e.g., the function should be named VERDICT: NEEDS_IMPROVEMENT Search Inside a Sorted Array whose Length is unknown (Problem_2.py)Your solution demonstrates a good understanding of binary search for rotated sorted arrays, but it does not address the problem given. The problem requires you to work with an Here are the key issues:
To correct this:
Example corrected approach: class Solution:
def search(self, reader, target):
low, high = 0, 1
while reader.get(high) < target:
low = high
high *= 2
while low <= high:
mid = low + (high - low) // 2
val = reader.get(mid)
if val == target:
return mid
elif val > target:
high = mid - 1
else:
low = mid + 1
return -1Please revise your solution to match the problem requirements. VERDICT: NEEDS_IMPROVEMENT Search a 2D Matrix (Problem_3.py)Note: The verdict should be PASS if the solution is correct and efficient, otherwise NEEDS_IMPROVEMENT. Note: The student's solution is for a different problem (Search in a Sorted Array of Unknown Size) and not for the Search a 2D Matrix problem. The student's code is for a problem where the array size is unknown and uses an ArrayReader interface, which is not relevant to the given problem. Therefore, the student's solution does not address the problem at all. Let's evaluate accordingly. VERDICT: NEEDS_IMPROVEMENT |
No description provided.