Skip to content

Conversation

@Anishluke92
Copy link
Owner

No description provided.

left_count
end

def distance_to_nearest_vowel(string)
Copy link
Collaborator

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.

Copy link
Owner Author

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

Copy link
Collaborator

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.

Copy link
Owner Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants