0
0
DSA Goprogramming~10 mins

Why Binary Search and What Sorted Order Gives You in DSA Go - Test Your Knowledge

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

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

DSA Go
mid := (low + [1]) / 2
Drag options to blanks, or click blank then click option'
Alow
Bhigh
Cmid
Dlen(arr)
Attempts:
3 left
💡 Hint
Common Mistakes
Using low twice instead of high
Using length of array directly
2fill in blank
medium

Complete the code to update the low index when target is greater than middle element.

DSA Go
if target > arr[mid] {
    [1] = mid + 1
}
Drag options to blanks, or click blank then click option'
Alow
Bhigh
Cmid
Dtarget
Attempts:
3 left
💡 Hint
Common Mistakes
Updating high instead of low
Not adding 1 to mid
3fill in blank
hard

Fix the error in the loop condition to correctly run binary search.

DSA Go
for low [1] high {
    mid := (low + high) / 2
    // rest of code
}
Drag options to blanks, or click blank then click option'
A<=
B<
C>
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using only less than which misses last element
Using greater than
4fill in blank
hard

Fill both blanks to create a map of word lengths for words longer than 3 characters.

DSA Go
lengths := map[string]int{}
for _, word := range words {
    if len(word) [1] 3 {
        lengths[word] = [2]
    }
}
Drag options to blanks, or click blank then click option'
A>
Blen(word)
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than instead of greater than
Storing word instead of length
5fill in blank
hard

Fill all three blanks to create a filtered map with uppercase keys and values greater than 0.

DSA Go
filtered := map[string]int{}
for k, v := range data {
    if v [1] 0 {
        filtered[[2]] = v
    }
}

// Convert keys to uppercase
for k := range filtered {
    newKey := [3]
    filtered[newKey] = filtered[k]
    delete(filtered, k)
}
Drag options to blanks, or click blank then click option'
A>
Bk
Cstrings.ToUpper(k)
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>'
Using value instead of key for map assignment
Not converting key to uppercase