0
0
DSA C++programming~10 mins

Find Minimum in Rotated Sorted Array in DSA C++ - Interactive Practice

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

Complete the code to return the first element of the array.

DSA C++
int findMin(vector<int>& nums) {
    return nums[[1]];
}
Drag options to blanks, or click blank then click option'
Anums.size()
B1
Cnums.size() - 1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 1 instead of 0
Using nums.size() which is out of bounds
2fill in blank
medium

Complete the code to find the middle index in binary search.

DSA C++
int left = 0, right = nums.size() - 1;
while (left < right) {
    int mid = (left [1] right) / 2;
    // rest of code
}
Drag options to blanks, or click blank then click option'
A+
B+ +
Attempts:
3 left
💡 Hint
Common Mistakes
Using only left or right
Using bit shifts incorrectly
3fill in blank
hard

Fix the error in the condition to check if mid element is greater than the right element.

DSA C++
if (nums[mid] [1] nums[right]) {
    left = mid + 1;
} else {
    right = mid;
}
Drag options to blanks, or click blank then click option'
A<
B==
C>
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of >
Using == which is incorrect here
4fill in blank
hard

Fill both blanks to complete the binary search loop and return the minimum element.

DSA C++
int left = 0, right = nums.size() - 1;
while ([1] < [2]) {
    int mid = (left + right) / 2;
    if (nums[mid] > nums[right]) {
        left = mid + 1;
    } else {
        right = mid;
    }
}
return nums[left];
Drag options to blanks, or click blank then click option'
Aleft
Bright
Cmid
Dnums.size()
Attempts:
3 left
💡 Hint
Common Mistakes
Using mid in the condition
Using nums.size() which is out of bounds
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each number to its square if the number is less than 5.

DSA C++
auto squares = std::unordered_map<int, int>{{
    { [1], [2] } for (int num : nums) if (num [3] 5)
}};
Drag options to blanks, or click blank then click option'
Anum
Bnum * num
C<
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<'
Using num instead of num * num for value