Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Home
Talentd Logo
Talentd

Your trusted platform to ace any job interviews, craft the perfect resumes, and land your dream jobs.

P
Featured on
Product Hunt
▲455
All services are online

Products

  • Resume Review
  • Company Prep Pack
  • DSA Corner
  • Jobs
  • Internships
  • Fresher Jobs
  • Roadmaps
  • Tax Calculator

Resources

  • Articles
  • DRDO Internships

Support

  • Contact Us

DSA & Interview Prep

  • DSA Questions
  • DSA Sheets
  • Company Questions
  • Topics

Company

  • Companies Hiring
  • About
  • Contact
  • Advertisement

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Delivery Policy

Popular Skills

Browse All Skills →

Popular Tags

Browse All Tags →

© 2025 Talentd.in - All rights reserved

Privacy PolicyTerms & Conditions
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
DSA Corner
DashboardQuestionsTopicsCompaniesSheets

Talentd Logo
Talentd

Your trusted platform to ace any job interviews, craft the perfect resumes, and land your dream jobs.

P
Featured on
Product Hunt
▲455
All services are online

Products

  • Resume Review
  • Company Prep Pack
  • DSA Corner
  • Jobs
  • Internships
  • Fresher Jobs
  • Roadmaps
  • Tax Calculator

Resources

  • Articles
  • DRDO Internships

Support

  • Contact Us

DSA & Interview Prep

  • DSA Questions
  • DSA Sheets
  • Company Questions
  • Topics

Company

  • Companies Hiring
  • About
  • Contact
  • Advertisement

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Delivery Policy

Popular Skills

Browse All Skills →

Popular Tags

Browse All Tags →

© 2025 Talentd.in - All rights reserved

Privacy PolicyTerms & Conditions
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
DSA Corner
DashboardQuestionsTopicsCompaniesSheets
Talentd Logo
Talentd

Your trusted platform to ace any job interviews, craft the perfect resumes, and land your dream jobs.

P
Featured on
Product Hunt
▲455
All services are online

Products

  • Resume Review
  • Company Prep Pack
  • DSA Corner
  • Jobs
  • Internships
  • Fresher Jobs
  • Roadmaps
  • Tax Calculator

Resources

  • Articles
  • DRDO Internships

Support

  • Contact Us

DSA & Interview Prep

  • DSA Questions
  • DSA Sheets
  • Company Questions
  • Topics

Company

  • Companies Hiring
  • About
  • Contact
  • Advertisement

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Delivery Policy

Popular Skills

Browse All Skills →

Popular Tags

Browse All Tags →

© 2025 Talentd.in - All rights reserved

Privacy PolicyTerms & Conditions
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
DSA Corner
DashboardQuestionsTopicsCompaniesSheets
Talentd Logo
Talentd

Your trusted platform to ace any job interviews, craft the perfect resumes, and land your dream jobs.

P
Featured on
Product Hunt
▲455
All services are online

Products

  • Resume Review
  • Company Prep Pack
  • DSA Corner
  • Jobs
  • Internships
  • Fresher Jobs
  • Roadmaps
  • Tax Calculator

Resources

  • Articles
  • DRDO Internships

Support

  • Contact Us

DSA & Interview Prep

  • DSA Questions
  • DSA Sheets
  • Company Questions
  • Topics

Company

  • Companies Hiring
  • About
  • Contact
  • Advertisement

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Delivery Policy

Popular Skills

Browse All Skills →

Popular Tags

Browse All Tags →

© 2025 Talentd.in - All rights reserved

Privacy PolicyTerms & Conditions
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
DSA Corner
DashboardQuestionsTopicsCompaniesSheets
Back to Problems

744. Find Smallest Letter Greater Than Target

Easy53.1% Acceptance
ArrayBinary Search
Asked by:
L
LinkedIn
Amazon
ProblemHints (1)Solutions (12)VideosCompanies (3)Notes

Problem Statement

You are given an array of characters letters that is sorted in non-decreasing order, and a character target. There are at least two different characters in letters.

Return the smallest character in letters that is lexicographically greater than target. If such a character does not exist, return the first character in letters.

Example 1:

Input: letters = ["c","f","j"], target = "a"
Output: "c"
Explanation: The smallest character that is lexicographically greater than 'a' in letters is 'c'.

Example 2:

Input: letters = ["c","f","j"], target = "c"
Output: "f"
Explanation: The smallest character that is lexicographically greater than 'c' in letters is 'f'.

Example 3:

Input: letters = ["x","x","y","y"], target = "z"
Output: "x"
Explanation: There are no characters in letters that is lexicographically greater than 'z' so we return letters[0].

Constraints:

  • 2 <= letters.length <= 104
  • letters[i] is a lowercase English letter.
  • letters is sorted in non-decreasing order.
  • letters contains at least two different characters.
  • target is a lowercase English letter.
Talentd Logo
Talentd

Your trusted platform to ace any job interviews, craft the perfect resumes, and land your dream jobs.

P
Featured on
Product Hunt
▲455
All services are online

Products

  • Resume Review
  • Company Prep Pack
  • DSA Corner
  • Jobs
  • Internships
  • Fresher Jobs
  • Roadmaps
  • Tax Calculator

Resources

  • Articles
  • DRDO Internships

Support

  • Contact Us

DSA & Interview Prep

  • DSA Questions
  • DSA Sheets
  • Company Questions
  • Topics

Company

  • Companies Hiring
  • About
  • Contact
  • Advertisement

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Delivery Policy

Popular Skills

Browse All Skills →

Popular Tags

Browse All Tags →

© 2025 Talentd.in - All rights reserved

Privacy PolicyTerms & Conditions
A
B
Bloomberg

Approach

In #744 Find Smallest Letter Greater Than Target, you are given a sorted array of lowercase characters and a target character. The task is to return the smallest letter strictly greater than the target. The array is circular, meaning if no character is greater than the target, the answer wraps around to the first element.

A straightforward idea is to scan the array linearly and track the first character greater than the target. While simple, this takes O(n) time.

Since the array is already sorted, a more efficient strategy is to apply binary search. The goal is to locate the first index where the character is strictly greater than the target. If the search moves past the last element, you return the first character due to the circular condition. This approach significantly improves efficiency.

The binary search technique reduces the search space each step, giving a time complexity of O(log n) while using constant extra space.

Complexity

ApproachTime ComplexitySpace Complexity
Linear ScanO(n)O(1)
Binary SearchO(log n)O(1)

Video Solution Available

Eric Programming

View all video solutions

Problem Hints

Use these hints if you're stuck. Try solving on your own first.

1
Hint 1

Try to find whether each of 26 next letters are in the given string array.

Ready to see the solutions?View Solutions

Solutions (12)

Brute Force Linear Scan

The simplest way to solve the problem is to iterate over the array and find the first character that is greater than the target character. If such a character is not found by the end of the array, the function should return the first character of the array. This approach simply checks each character in order from left to right, comparing it with the target.

Time Complexity: O(n) where n is the size of the array since each element may be checked in the worst case.
Space Complexity: O(1) as only a constant amount of space is used.

CC++JavaPythonC#JavaScript
1#include <stdio.h>
2
3char nextGreatestLetter(char* letters, int lettersSize, char target) {
4    for (int i = 0;

Explanation

The function iterates through each element in the letters array. As soon as it finds a letter that is greater than target, it returns that letter. If no such letter is found, it returns the first element of the array since the array is viewed in a circular manner.

Binary Search

Utilizing the sorted nature of the array, we can employ a binary search technique to pinpoint the smallest character that exceeds the target. By continually narrowing the search range, we can efficiently determine the desired character. If the binary search concludes without finding a suitable character, the array's initial character is returned.

Time Complexity: O(log n), hinging on halving the array.
Space Complexity: O(1), processing is constant-space.

CC++JavaPythonC#JavaScript
1

Video Solutions

Watch expert explanations and walkthroughs

[Java] Leetcode 744. Find Smallest Letter Greater Than Target [Binary Search #3]

Eric Programming
6:407,957 views

Asked By Companies

3 companies
L
LinkedIn
A
Amazon
B
Bloomberg

Prepare for Interviews

Practice problems asked by these companies to ace your technical interviews.

Explore More Problems

Notes

Personal Notes

Jot down your thoughts, approach, and key learnings

0 characters

Similar Problems

Median of Two Sorted ArraysHard
Search in Rotated Sorted ArrayMedium
Find First and Last Position of Element in Sorted ArrayMedium
Search Insert PositionEasy
More similar problems

Related Topics

ArrayBinary Search

Problem Stats

Acceptance Rate53.1%
DifficultyEasy
Companies3

Practice on LeetCode

Solve with full IDE support and test cases

Solve Now

Frequently Asked Questions

Why does this problem use a circular condition?

The problem states that the letters wrap around. This means if no character in the array is greater than the target, the answer should be the first character in the array. This ensures a valid result always exists.

Is Find Smallest Letter Greater Than Target asked in coding interviews?

Yes, this type of problem is common in coding interviews because it tests understanding of binary search variations. Many companies ask similar questions to evaluate search optimization and boundary handling.

What data structure is used in Find Smallest Letter Greater Than Target?

The main data structure used is a sorted array of characters. The binary search algorithm operates on this array to efficiently locate the smallest character greater than the target.

What is the optimal approach for Find Smallest Letter Greater Than Target?

The optimal approach uses binary search because the array of characters is already sorted. By finding the first element strictly greater than the target, we can reduce the time complexity to O(log n) instead of scanning the entire array.

i
<
lettersSize
;
i
++
)
{
5
if
(
letters
[
i
]
>
target
)
{
6
return
letters
[
i
]
;
7
}
8
}
9
return
letters
[
0
]
;
10
}
#
include
<stdio.h>
2
3
char
nextGreatestLetter
(
char
*
letters
,
int
lettersSize
,
char
target
)
{
4
int
low
=
0
,
high
=
lettersSize
-
1
;
5
while
(
low
<=
high
)
{
6
int
mid
=
low
+
(
high
-
low
)
/
2
;
7
if
(
letters
[
mid
]
<=
target
)
{
8
low
=
mid
+
1
;
9
}
else
{
10
high
=
mid
-
1
;
11
}
12
}
13
return
letters
[
low
%
lettersSize
]
;
14
}

Explanation

This function relies on the binary search algorithm. The search confines focus to the mid-value, adjusting based on its comparison to target. If mid is greater, the search shifts left; otherwise, right. Upon termination, the remainder of low mod lettersSize returns the correct character for the circular case.