0
0
DSA Goprogramming~10 mins

Search in Rotated Sorted Array in DSA Go - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to return -1 if the array is empty.

DSA Go
if len(nums) == 0 {
    return [1]
}
Drag options to blanks, or click blank then click option'
A1
B-1
C0
Dlen(nums)
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 0 which could be confused with a valid index.
Returning length of the array which is out of index range.
2fill in blank
medium

Complete the code to calculate the middle index correctly.

DSA Go
mid := [1] + (high - low) / 2
Drag options to blanks, or click blank then click option'
Ahigh
Blen(nums)
Clow
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using high directly which can cause index out of range.
Using 0 which ignores the current search range.
3fill in blank
hard

Fix the error in the condition to check if the left half is sorted.

DSA Go
if nums[[1]] <= nums[mid] {
Drag options to blanks, or click blank then click option'
Ahigh
B0
Cmid
Dlow
Attempts:
3 left
💡 Hint
Common Mistakes
Using high or mid index incorrectly in the condition.
Using 0 which may not be the current low index.
4fill in blank
hard

Fill both blanks to check if the target is in the left sorted half.

DSA Go
if target >= nums[[1]] && target < nums[[2]] {
    high = mid - 1
} else {
    low = mid + 1
}
Drag options to blanks, or click blank then click option'
Alow
Bmid
Chigh
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using high instead of mid in the second comparison.
Using 0 which may not be the current low index.
5fill in blank
hard

Fill all three blanks to check if the target is in the right sorted half.

DSA Go
if target > nums[[1]] && target <= nums[[2]] {
    [3] = mid + 1
} else {
    high = mid - 1
}
Drag options to blanks, or click blank then click option'
Alow
Bmid
Chigh
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using low instead of mid or high in comparisons.
Updating wrong variable in the assignment.