-
Notifications
You must be signed in to change notification settings - Fork 1
Distance to nearest vowel #116
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
base: master
Are you sure you want to change the base?
Conversation
| left_count | ||
| end | ||
|
|
||
| def distance_to_nearest_vowel(string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you try optimise the algorithm? if the word has 5 letters, then for each letter, you are doing two loops in the calculation method. So that's 5 * 2 = 10 times that you go through the whole input array. Could you try and reduce that to improve performance?
Step 1 is done. Getting it to work.
Step 2 - optimising performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did try optimizing the performance but didn't work out. Can you suggest me a way i could optimize the performance. so i will get an idea how to approach in getting a good performance and i can work on it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try this algorithm:
Loop from the left to right, as you go along mark the difference from left vowels.
The do the same from right to left, but only replace if the number is lower than the one computed already.
So in the end there will only be two loops then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically I'm looping from left to right (0 to target element ) and right to left (last element to target). but the only thing is i have created a function that will loop and return the closest value and then that value is stored into an array called result. i have a main loop that just gives the index which is the target.
I tried your algorithm but still i do need a third loop to set as the marker.
No description provided.