Skip to content
Y
yTube.SITE v8.0.4
media / worlds / tools / internet oddities
YouTube / video information

LeetCode 744 | Find Smallest Letter Greater Than Target | Java | Easy | Binary Search | CodeByTushu

Video information, playback and saved actions.

LeetCode 744 | Find Smallest Letter Greater Than Target | Java | Easy | Binary Search | CodeByTushu

Description: πŸš€ Welcome Back to CodeByTushu!

In today’s video, we solve LeetCode 744 β€” Find Smallest Letter Greater Than Target using Binary Search Upper Bound in Java.

We are given a non-decreasing sorted array of characters and a target character. We need to find the smallest character strictly greater than the target. If no such character exists in the array, the problem requires wrapping around and returning the very first character of the array. Since the input array is already sorted, we can avoid a linear search and directly locate the answer in logarithmic time.

We implement an optimal binary search equivalent to finding the upper bound of target. At each midpoint, if the character is less than or equal to target, we advance the left pointer; otherwise, we narrow down the right boundary. Upon search termination, we return letters[left % letters.length], which naturally handles the wrap-around case to letters[0] in a single clean expression without extra conditions.

πŸ”₯ Problem Highlights

βœ… Given array is already sorted in non-decreasing order
βœ… Problem directly translates to an Upper Bound binary search
βœ… Eliminates linear search overhead by halving search space in O(log N)
βœ… Gracefully handles duplicate characters in the sorted array
βœ… Modulo arithmetic (left % n) effortlessly implements wrap-around
βœ… Time Complexity: O(log N) | Auxiliary Space Complexity: O(1)

⏱️ TIMESTAMPS

00:00 Intro
00:54 Problem Understanding
01:51 Key Observation
03:29 Binary Search Upper Bound Approach
04:31 Java Code Walkthrough
05:40 Execution & Test Cases
07:08 Time Complexity Analysis
07:52 Space Complexity Analysis
08:27 Outro & Wrap-up

πŸ“‚ Problem Folder & Detailed Documentation:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/tree/main/solutions/January/31-January/744-Find-Smallest-Letter-Greater-Than-Target

β˜• Java Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/January/31-January/744-Find-Smallest-Letter-Greater-Than-Target/Solution.java

🐍 Python Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/January/31-January/744-Find-Smallest-Letter-Greater-Than-Target/solution.py

⚑ C++ Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/January/31-January/744-Find-Smallest-Letter-Greater-Than-Target/solution.cpp

🌐 JavaScript Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/January/31-January/744-Find-Smallest-Letter-Greater-Than-Target/solution.js

πŸ”— LeetCode Source Code

πŸ“Œ Admin type the link

🌐 All LeetCode Solutions

πŸ“Œ https://codebytushu.com/Leetcode/

πŸ“± Join CodeByTushu on WhatsApp

Get coding updates, LeetCode solutions, daily questions and more.

https://whatsapp.com/channel/0029Vb8k5mCDeON2Xwlkxe40

❀️ Donate

πŸ“Œ https://codebytushu.com/Leetcode/donate.php

πŸ”₯ Perfect For

LeetCode Easy Problems
Java DSA Preparation
Binary Search Patterns
Upper Bound Algorithm
Array Search Optimization
Coding Interview Preparation
Problem Solving

🌐 Follow CodeByTushu

▢️ YouTube: https://www.youtube.com/@codebytushu

πŸ“Έ Instagram: https://instagram.com/codebytushu/

πŸ’Ό LinkedIn: https://www.linkedin.com/company/codebytushu/

🌍 Website: https://codebytushu.com

πŸ™ GitHub: https://github.com/CodeByTushu

❀️ Don’t Forget To

πŸ‘ Like | πŸ’¬ Comment | πŸ”” Subscribe

πŸ’¬ Question of the Day

Why does letters[left % letters.length] correctly handle the wrap-around condition when no character is strictly greater than target?

1️⃣ The modulo operator returns the median element when left equals n
2️⃣ When no element is greater, left equals letters.length, and letters.length % letters.length evaluates to 0, returning letters[0]
3️⃣ Binary search forces left to be -1 when target is not found
4️⃣ Modulo arithmetic reverses the sorted character array

#LeetCode744 #LeetCode #FindSmallestLetterGreaterThanTarget #Java #JavaDSA #BinarySearch #UpperBound #Array #DSA #CodingInterview #ProblemSolving #LeetCodeEasy #DailyLeetCode #JavaProgramming #CodeByTushu

πŸ‘‡ Comment the answer below! πŸ”₯Β Close description
Β Β Β Β Β Β 
Videos related to "LeetCode 744 | Find Smallest Letter Greater Than Target | Java | Easy | Binary Search | CodeByTushu"

Related videos are temporarily unavailable.

Try again, or come back later.