Skip to content
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

Layla - Edges - palidrome #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

lbristol88
Copy link

The time complexity is O(n) because there is only one loop running in my solution. The space complexity is O(1) because the algorithm is just checking the string and not copying anything.

@shrutivanw
Copy link

Nice work.

Wrt time and space complexity: Always explain what n stands for while explaining your time and space complexity. That along with your explanation for reasoning behind your answer, is the complete answer for the time and space complexity. In this case, n is the number of characters in the input string parameter.

The number loops don't directly influence the time complexity. It's the number of steps or operations in your algorithm that determines the time complexity. In your algorithm, each character in the input string that is a white space is compared to a white space once, and each character that is not a white space is first compared to a white space and then compared to another character that is not a white space. So, each character is compared at the most twice. If there are n characters in the input string, then the number of comparisons would be at the most 2 times n or O(n).

Slack me if you'd like to discuss further or have any questions.

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