Conversation
| left_count | ||
| end | ||
|
|
||
| def distance_to_nearest_vowel(string) |
There was a problem hiding this comment.
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.
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.
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.
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.