Skip to content

Conversation

@Dhar01
Copy link
Contributor

@Dhar01 Dhar01 commented Nov 13, 2025

Challenge 1 Solution

Submitted by: @Dhar01
Challenge: Challenge 1

Description

This PR contains my solution for Challenge 1.

Changes

  • Added solution file to challenge-1/submissions/Dhar01/solution-template.go

Testing

  • Solution passes all test cases
  • Code follows Go best practices

Thank you for reviewing my submission! 🚀

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 13, 2025

Walkthrough

A new Go solution file is introduced for Challenge 1 that implements a Sum function accepting two integers and returning their sum if both inputs fall within the [-1e9, 1e9] range, otherwise returning 0. A main function reads two comma-separated integers from standard input and prints the result.

Changes

Cohort / File(s) Change Summary
New Challenge 1 Solution
challenge-1/submissions/Dhar01/solution-template.go
Added complete Go program with main entry point that reads two integers via fmt.Scanf with format "%d, %d", calls Sum(a, b) to compute their sum with bounds validation, and prints the result.

Sequence Diagram(s)

sequenceDiagram
    participant Main as main()
    participant Scanf as fmt.Scanf
    participant Sum as Sum(a, b)
    participant Math as math.Pow

    Main->>Scanf: Read "%d, %d" from stdin
    Scanf-->>Main: a, b, err
    alt Input Read Error
        Main->>Main: Handle error
    else Input Valid
        Main->>Sum: Call Sum(a, b)
        Sum->>Math: Calculate bounds ±1e9
        alt Both in [-1e9, 1e9]
            Sum-->>Main: Return a + b
        else Out of bounds
            Sum-->>Main: Return 0
        end
        Main->>Main: fmt.Println(result)
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Straightforward new file addition with basic I/O and arithmetic
  • Bounds validation logic using math.Pow is the primary complexity point
  • Standard input pattern using fmt.Scanf with clear format string

Possibly related PRs

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change - adding a Challenge 1 solution submission by Dhar01, which matches the changeset containing a new solution file.
Description check ✅ Passed The description is directly related to the changeset, clearly explaining that it contains a Challenge 1 solution submission with the specific file path, testing status, and code quality claims.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 061d7c7 and f6325ec.

📒 Files selected for processing (1)
  • challenge-1/submissions/Dhar01/solution-template.go (1 hunks)

Comment on lines +25 to +30
lowerLimit := math.Pow(-10, 9)
higherLimit := math.Pow(10, 9)

if int(lowerLimit) <= a && b <= int(higherLimit) {
return a + b
}
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.

@RezaSi RezaSi merged commit d10fcc9 into RezaSi:main Nov 15, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants