Skip to content

Solution #14 - Daniel/Edited - 16.03.2025 #36

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

danzang100
Copy link

Solution and Explanation uploaded

@JRS296 JRS296 self-requested a review March 17, 2025 12:42
Copy link
Member

@JRS296 JRS296 left a comment

Choose a reason for hiding this comment

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

Kindly make the requested changes and do the same for the other PR's as well

Comment on lines +9 to +21
### 1. Lexicographic Sorting

1. Lexicographically sorting the array
2. Comparing the first and last of the sorted array for prefix.
3. Create an empty string called prefix.
4. Iteratively, go through the characters to add matching characters to the prefix string.
5. When there is a mismatch, end the loop and return the prefix string.

- Since we are lexicographically sorting the array, the first and last string are the most different. Finding the common prefix between the two, would be the longest common prefix for all the strings in the array between them.

#### Time Complexity

O(nlogn) because we sort the array, traversing the two strings will be done in O(n) time which is overshadowed by the worser time complexity O(nlogn).
Copy link
Member

Choose a reason for hiding this comment

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

Much better! Kindly add the solutions corresponding to the explanation as well into the cpp file

Copy link
Member

@JRS296 JRS296 left a comment

Choose a reason for hiding this comment

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

Kindly add the solutions corresponding to the explanation as well into the cpp file

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