Anyone think they know the answer? Post below!
Coding Challenge: Can You Spot the Bug?
5 Comments
The for loop has to go upto word.length/2
I am assuming this code is in C language from the looks of the syntax used.
so, it should be
for (int i = 0; i < word.length/2; i++)
not in touch with C language for a very long time, so I think that word.length is also incorrect.
there has to be a function to get the length of a null-terminated string of C. it should be
strlen(word) and not word.length
Also the return type for the function is missing.
Curious to know the programming language of the code.
Please log in to add a comment.
Yes! You nailed it :)
We currently run into 2 out of bound exceptions
- The initial for loop will break since it goes i < word.length instead of i < word.length - 1. And like you mentioned, an even better solution in this case is i < word.length / 2 since we can confirm its a palindrome after iterating halfway through the array
- We also need to address the comparison line. So it would be if (word[i] !== word[word.length - 1 - i])
And its just some Pseudocode! Its not an actual language (although I based it off a mixture of C and Python :) )
Please log in to add a comment.
Please log in to comment on this post.
More Posts
- © 2026 Coder Legion
- Feedback / Bug
- Privacy
- About Us
- Contacts
- Premium Subscription
- Terms of Service
- Refund
- Early Builders
More From BeyondCode
Related Jobs
- Full Stack Java/Go Developer (Bilingual English/Spanish)Dev Technology · Full time · Arlington, VA
- Backend Software Developer - Agile, CI/CD & DebuggingIBM Computing · Full time · Austin, TX
- Android Developer: Debug, Build & Improve AppsTechDigital Group · Full time · San Jose, CA
Commenters (This Week)
Contribute meaningful comments to climb the leaderboard and earn badges!