Next Alphabetical Element
Easy

Problem Statement

Given a sorted array of characters `letters` and a `target` character, find the smallest character in the array that is strictly greater than the `target`. If no such character exists, handle accordingly (e.g., wrap around or return a default value).

Examples

1Example 1
Input:
{ "letters": [ "c", "f", "j" ], "target": "a" }
Output:
"c"
2Example 2
Input:
{ "letters": [ "c", "f", "j" ], "target": "c" }
Output:
"f"
3Example 3
Input:
{ "letters": [ "c", "f", "j" ], "target": "d" }
Output:
"f"
Loading...

Sign in to Run Code and Submit