educative.io

Next Letter Medium -- directions confusion?

I’ve been rereading the prompt for this question, and find it confusing. Pasting the prompt as is below:

Given an array of lowercase letters sorted in ascending order, find the smallest letter in the given array greater than a given ‘key’.

Assume the given array is a circular list, which means that the last letter is assumed to be connected with the first letter. This also means that the smallest letter in the given array is greater than the last letter of the array and is also the first letter of the array.

I bolded the parts that feel contradictory… So it’s an array in ascending order, from smallest letter to largest. Makes sense that the smallest letter of the array would be the first letter, but then it says the first letter is also greater than the last letter of the array. If it’s ascending order, how can that be possible? I understand that the goal is to create a cycle between the arr end to start, but maybe this wording could be clarified?


Type your question above this line.

Course: https://www.educative.io/collection/5668639101419520/5671464854355968
Lesson: https://www.educative.io/collection/page/5668639101419520/5671464854355968/4850551927865344

Hi djbaklava, example 4 given in the lesson can clear your confusion where h is the given key and we have to find out the element next to h. Since we’ve already h as the last element of the array so the element next to h is a. Here a is next to h and h comes first so we can say that the smallest letter in the given array is greater than the last letter of the array and is also the first letter of the array.
Here’s another example for your understanding:
[a, d, g, j] key=m
The element next to m is a. Now m is greater than the j and is also the first element of the array.
I hope it will clear your confusion. If you still have any issues then please let me know.