PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000081. Ký tự nhỏ nhất lớn hơn mục tiêu (Find Smallest Letter Greater Than Target)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Ký tự nhỏ nhất lớn hơn mục tiêu (Find Smallest Letter Greater Than Target)
Find Smallest Letter Greater Than Target
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given a sorted array of lowercase English letters containing at least two distinct letters and a target letter , return the smallest letter strictly greater than ; wrap around to the first letter if none exists.
Input
The first line contains . The second line contains space-separated lowercase letters, and the third line contains .
Output
Print the requested lowercase letter.
Subtasks
- Subtask 1 (20 points): ; all letters and are lowercase
a–z; the array is non-decreasing and has at least two distinct letters. - Subtask 2 (30 points): ; all letters and are lowercase
a–z; the array is non-decreasing and has at least two distinct letters. - Subtask 3 (50 points): ; all letters and are lowercase
a–z; the array is non-decreasing and has at least two distinct letters.
Examples
Input
3
c f j
c
Output
f
Explanation
The letters are c, f, j and the target is c. Equal is not allowed. Both f and j qualify; the smaller is f.