Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions challenge-1/submissions/Dhar01/solution-template.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"fmt"
"math"
)

func main() {
var a, b int
// Read two integers from standard input
_, err := fmt.Scanf("%d, %d", &a, &b)
if err != nil {
fmt.Println("Error reading input:", err)
return
}

// Call the Sum function and print the result
result := Sum(a, b)
fmt.Println(result)
}

// Sum returns the sum of a and b.
func Sum(a int, b int) int {
// TODO: Implement the function
lowerLimit := math.Pow(-10, 9)
higherLimit := math.Pow(10, 9)

if int(lowerLimit) <= a && b <= int(higherLimit) {
return a + b
}
Comment on lines +25 to +30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Range enforcement is incomplete

Only a is checked against the lower bound and only b against the upper bound, so values like a = 1_000_000_001 or b = -1_000_000_001 still return a non-zero sum—breaking the spec that both operands must stay within [-1e9, 1e9]. Tighten the condition to cover both bounds for both operands.

-func Sum(a int, b int) int {
-	// TODO: Implement the function
-	lowerLimit := math.Pow(-10, 9)
-	higherLimit := math.Pow(10, 9)
-	
-	if int(lowerLimit) <= a && b <= int(higherLimit) {
-	    return a + b
-	}
-	
-	return 0
+func Sum(a int, b int) int {
+	const lowerLimit = -1_000_000_000
+	const upperLimit = 1_000_000_000
+
+	if a < lowerLimit || a > upperLimit || b < lowerLimit || b > upperLimit {
+		return 0
+	}
+
+	return a + b
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
lowerLimit := math.Pow(-10, 9)
higherLimit := math.Pow(10, 9)
if int(lowerLimit) <= a && b <= int(higherLimit) {
return a + b
}
func Sum(a int, b int) int {
const lowerLimit = -1_000_000_000
const upperLimit = 1_000_000_000
if a < lowerLimit || a > upperLimit || b < lowerLimit || b > upperLimit {
return 0
}
return a + b
}
🤖 Prompt for AI Agents
In challenge-1/submissions/Dhar01/solution-template.go around lines 25 to 30,
the range check only validates the lower bound for `a` and the upper bound for
`b`, allowing out-of-range values for the other sides; change the condition to
ensure both `a` and `b` are each >= -1e9 and <= 1e9 (i.e., check lower and upper
bounds for both operands) and return the sum only when both pass, otherwise
handle the out-of-range case as intended.


return 0
}
Loading