-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind-smallest-letter-greater-than-target.html
40 lines (30 loc) · 1.44 KB
/
find-smallest-letter-greater-than-target.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<p>Given a characters array <code>letters</code> that is sorted in <strong>non-decreasing</strong> order and a character <code>target</code>, return <em>the smallest character in the array that is larger than </em><code>target</code>.</p>
<p><strong>Note</strong> that the letters wrap around.</p>
<ul>
<li>For example, if <code>target == 'z'</code> and <code>letters == ['a', 'b']</code>, the answer is <code>'a'</code>.</li>
</ul>
<p> </p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> letters = ["c","f","j"], target = "a"
<strong>Output:</strong> "c"
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> letters = ["c","f","j"], target = "c"
<strong>Output:</strong> "f"
</pre>
<p><strong>Example 3:</strong></p>
<pre>
<strong>Input:</strong> letters = ["c","f","j"], target = "d"
<strong>Output:</strong> "f"
</pre>
<p> </p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 <= letters.length <= 10<sup>4</sup></code></li>
<li><code>letters[i]</code> is a lowercase English letter.</li>
<li><code>letters</code> is sorted in <strong>non-decreasing</strong> order.</li>
<li><code>letters</code> contains at least two different characters.</li>
<li><code>target</code> is a lowercase English letter.</li>
</ul>