Skip to content

Longest Common Prefix #5933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed

Longest Common Prefix #5933

wants to merge 9 commits into from

Conversation

mrinalchauhan
Copy link

Here is the Approach :

1)Sort the Array: Sort the array of strings to bring strings with common prefixes adjacent to each other.

2)Identify Extremes: Select the first and last strings from the sorted array for comparison, as they will have the longest common prefix.

3)Character Comparison: Compare the characters of the first and last strings until a mismatch is found, tracking the index of the last matching character.

4)Return Prefix: Return the substring of the first string from the start to the index of the last matching character, which represents the longest common prefix.

@codecov-commenter
Copy link

codecov-commenter commented Oct 21, 2024

Codecov Report

Attention: Patch coverage is 0% with 24 lines in your changes missing coverage. Please review.

Project coverage is 66.69%. Comparing base (e499d3b) to head (4df41d6).
Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
...com/thealgorithms/strings/LongestCommonPrefix.java 0.00% 24 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #5933      +/-   ##
============================================
- Coverage     66.80%   66.69%   -0.11%     
+ Complexity     4501     4500       -1     
============================================
  Files           611      612       +1     
  Lines         16958    16982      +24     
  Branches       3275     3284       +9     
============================================
- Hits          11328    11326       -2     
- Misses         5182     5207      +25     
- Partials        448      449       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@siriak siriak left a comment

Choose a reason for hiding this comment

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

Please replace main with JUnit tests and fix PR checks

@mrinalchauhan mrinalchauhan closed this by deleting the head repository Oct 23, 2024
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