Back to Browse

1903. Largest Odd Number in String | LeetCode Easy | C++ Solution | Step-by-Step Explanation

4 views
May 19, 2026
5:42

Problem Name: 1903. Largest Odd Number in String In this video, I solved the LeetCode Easy problem “Largest Odd Number in String” using C++ with an easy step-by-step explanation. 📌 Problem Statement: Given a string num representing a large integer, return the largest-valued odd integer (as a string) that is a non-empty substring of num. 📌 Approach Used: - Traverse the string from the last character - Check whether current digit is odd or not - If odd digit is found: - create answer string - copy all characters from index 0 till that index - return the answer - If no odd digit exists, return empty string 📌 Main Logic: An odd number always ends with: 1, 3, 5, 7, or 9 📌 Example: Input: num = "35427" Output: "35427" Explanation: Last digit 7 is odd, so entire string becomes answer. 📌 Concepts Covered: ✅ Strings ✅ Traversal ✅ Nested Loops ✅ Character Operations ✅ Odd & Even Logic 📌 Time Complexity: O(n) 📌 Space Complexity: O(n) 📌 Language Used: C++ 📌 Features: ✅ Beginner Friendly ✅ Step-by-Step Explanation ✅ Dry Run Included ✅ Easy C++ Solution ✅ Interview Preparation 🔗 GitHub: https://github.com/amankumar1508 🔗 LinkedIn: / aman-kumar-067825379 🔗 Portfolio: https://aman-kumar-dev-portfolio.verc... 🔗 LeetCode Profile: https://leetcode.com/u/OVzm6rcAP2/ #leetcode #cplusplus #cpp #leetcode1903 #strings #dsa #coding #programming

Download

0 formats

No download links available.

1903. Largest Odd Number in String | LeetCode Easy | C++ Solution | Step-by-Step Explanation | NatokHD