Longest Common Prefix
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 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 :warning: |
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
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.