0
0
DSA Goprogramming~10 mins

Aggressive Cows Maximum Minimum Distance 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 sort the stall positions.

DSA Go
sort.[1](stalls)
Drag options to blanks, or click blank then click option'
AInts
BSlice
CFloat64s
DStrings
Attempts:
3 left
💡 Hint
Common Mistakes
Using sort.Strings on integer slice causes compile error.
Trying to sort without importing sort package.
2fill in blank
medium

Complete the code to check if cows can be placed with given minimum distance.

DSA Go
if stalls[i]-lastPos >= [1] {
Drag options to blanks, or click blank then click option'
AmidDist
BminDist
CmaxDist
Ddistance
Attempts:
3 left
💡 Hint
Common Mistakes
Using maxDist instead of minDist causes wrong logic.
Comparing with midDist which is not defined here.
3fill in blank
hard

Fix the error in the binary search loop condition.

DSA Go
for low <= [1] {
Drag options to blanks, or click blank then click option'
Ahigh
Bmid
Clow
DmaxDist
Attempts:
3 left
💡 Hint
Common Mistakes
Using low < mid causes infinite loop.
Using high < low reverses the condition.
4fill in blank
hard

Fill both blanks to update the binary search bounds correctly.

DSA Go
if canPlaceCows(stalls, cows, [1]) {
    result = [2]
    low = mid + 1
} else {
    high = mid - 1
}
Drag options to blanks, or click blank then click option'
Amid
Blow
Dhigh
Attempts:
3 left
💡 Hint
Common Mistakes
Updating result to low or high instead of mid.
Incorrectly updating low or high bounds.
5fill in blank
hard

Fill all three blanks to complete the canPlaceCows function logic.

DSA Go
count := 1
lastPos := stalls[0]
for i := 1; i < len(stalls); i++ {
    if stalls[i]-lastPos >= [1] {
        count++
        lastPos = stalls[i]
        if count == [2] {
            return [3]
        }
    }
}
return false
Drag options to blanks, or click blank then click option'
AminDist
Bcows
Ctrue
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Returning false instead of true when all cows placed.
Using wrong variable names for count or distance.