Skip to content

Add unit tests and a complexity analysis docstring for the "Count Asterisks" problem. - #47

Merged
kobukuro merged 4 commits into
mainfrom
test/add-count-asterisks-tests
Feb 26, 2026
Merged

kobukuro merged 4 commits into
mainfrom
test/add-count-asterisks-tests

Conversation

@kobukuro

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings February 26, 2026 01:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a Maven-structured solution + JUnit coverage for LeetCode 2315 (“Count Asterisks”), along with an in-code complexity analysis.

Changes:

  • Introduces CountAsterisks2315 under src/main/java/com/leetcode/easy with a complexity docstring.
  • Adds JUnit 5 tests for the three canonical examples.
  • Removes the legacy default-package implementation under src/.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/test/java/com/leetcode/easy/CountAsterisks2315Test.java Adds unit tests for example inputs (but test method names are currently misnamed).
src/main/java/com/leetcode/easy/CountAsterisks2315.java Adds solution implementation plus time/space complexity documentation.
src/CountAsterisks2315.java Removes old default-package version (including main).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +17 to +18
void testTwoSum_Example1() {
String s = "l|*e*et|c**o|*de|";

Copilot AI Feb 26, 2026

Copy link

Choose a reason for hiding this comment

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

Test method name appears copy/pasted from TwoSum; it should reflect the behavior under test (e.g., countAsterisks) to keep test reports/readability accurate.

Copilot uses AI. Check for mistakes.
Comment on lines +26 to +27
void testTwoSum_Example2() {
String s = "iamprogrammer";

Copilot AI Feb 26, 2026

Copy link

Choose a reason for hiding this comment

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

Test method name appears copy/pasted from TwoSum; it should reflect the behavior under test (e.g., countAsterisks) to keep test reports/readability accurate.

Copilot uses AI. Check for mistakes.
Comment on lines +35 to +36
void testTwoSum_Example3() {
String s = "yo|uar|e**|b|e***au|tiful";

Copilot AI Feb 26, 2026

Copy link

Choose a reason for hiding this comment

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

Test method name appears copy/pasted from TwoSum; it should reflect the behavior under test (e.g., countAsterisks) to keep test reports/readability accurate.

Copilot uses AI. Check for mistakes.
Comment on lines +7 to +14
* Breakdown:
* - Split operation: s.split("\\|") iterates through the entire string - O(n)
* - Outer loop: Iterates through half of the segments - O(n/2)
* - Inner loop: Total characters checked is at most n - O(n)
* <p>
* Space complexity: O(n)
* Breakdown:
* - Array storage: String[] words stores segments - O(n)

Copilot AI Feb 26, 2026

Copy link

Choose a reason for hiding this comment

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

The complexity breakdown mixes units: the outer loop is proportional to the number of split segments (words.length/2), not n/2 (n = string length). Consider defining a variable like m = words.length (with m <= n+1) and expressing the loop cost in terms of m to keep the analysis precise.

Suggested change
* Breakdown:
* - Split operation: s.split("\\|") iterates through the entire string - O(n)
* - Outer loop: Iterates through half of the segments - O(n/2)
* - Inner loop: Total characters checked is at most n - O(n)
* <p>
* Space complexity: O(n)
* Breakdown:
* - Array storage: String[] words stores segments - O(n)
* Let n = s.length() and m = words.length (the number of split segments), where m <= n + 1.
* Breakdown:
* - Split operation: s.split("\\|") iterates through the entire string - O(n)
* - Outer loop: Iterates through about half of the segments - O(m/2) = O(m)
* - Inner loop: Across all iterations, the total number of characters checked is at most n - O(n)
* Overall: O(n)
* <p>
* Space complexity: O(n)
* - Array storage: String[] words holds m references to substrings whose total length is O(n) - O(n)

Copilot uses AI. Check for mistakes.
@kobukuro

Copy link
Copy Markdown
Owner Author

@copilot open a new pull request to apply changes based on the comments in this thread

Copilot AI commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

@kobukuro I've opened a new pull request, #48, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 2 commits February 26, 2026 01:24
[WIP] Add unit tests and complexity analysis for Count Asterisks problem

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +18 to +21
String[] words = s.split("\\|");
int res = 0;
for (int i = 0; i < words.length; i = i + 2) {
for (int j = 0; j < words[i].length(); j++) {

Copilot AI Feb 26, 2026

Copy link

Choose a reason for hiding this comment

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

String[] words = s.split("\\|") produces pipe-delimited segments rather than "words". Renaming this local variable to something like segments/parts would make the loops and the complexity comment easier to follow.

Copilot uses AI. Check for mistakes.
* Breakdown:
* - Split operation: s.split("\\|") iterates through the entire string - O(n)
* - Outer loop: Iterates through about half of the segments - O(m/2) = O(m)
* - Inner loop: Across all iterations, the total number of characters checked is at most n - O(n)

Copilot AI Feb 26, 2026

Copy link

Choose a reason for hiding this comment

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

In the complexity breakdown, the statement "the total number of characters checked is at most n - O(n)" is not valid Big-O notation. Consider rephrasing to something like "at most n characters, so O(n)" to avoid the subtraction form.

Suggested change
* - Inner loop: Across all iterations, the total number of characters checked is at most n - O(n)
* - Inner loop: Across all iterations, the total number of characters checked is at most n characters, so O(n)

Copilot uses AI. Check for mistakes.
* Overall: O(n)
* <p>
* Space complexity: O(n)
* - Array storage: String[] words holds m references to substrings whose total length is O(n) - O(n)

Copilot AI Feb 26, 2026

Copy link

Choose a reason for hiding this comment

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

The space complexity bullet says the substrings total length is "O(n) - O(n)", which reads like a typo and is mathematically confusing. It should just state that the total substring storage is O(n) (or clarify what is being subtracted, if anything).

Suggested change
* - Array storage: String[] words holds m references to substrings whose total length is O(n) - O(n)
* - Array storage: String[] words holds m references to substrings whose total length is O(n)

Copilot uses AI. Check for mistakes.
@kobukuro
kobukuro merged commit f39a287 into main Feb 26, 2026
5 checks passed
@kobukuro
kobukuro deleted the test/add-count-asterisks-tests branch February 26, 2026 01:36
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.

3 participants