From 7b9a59172e3875f1efd8b31472e4e6ad9420d1de Mon Sep 17 00:00:00 2001 From: Sumit-Rajak99 Date: Sun, 17 Aug 2025 22:14:09 +0530 Subject: [PATCH] largest --- leetcode2264.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 leetcode2264.cpp diff --git a/leetcode2264.cpp b/leetcode2264.cpp new file mode 100644 index 0000000..823fa8a --- /dev/null +++ b/leetcode2264.cpp @@ -0,0 +1,31 @@ +#include +#include +using namespace std; + +// Function to find largest good integer +string largestGoodInteger(string num) { + string ans = ""; + for (int i = 0; i + 2 < num.size(); i++) { + if (num[i] == num[i+1] && num[i] == num[i+2]) { + string candidate = num.substr(i, 3); + if (ans == "" || candidate > ans) { + ans = candidate; + } + } + } + return ans; +} + +int main() { + string num; + cout << "Enter a string of digits: "; + cin >> num; + + string result = largestGoodInteger(num); + if (result == "") + cout << "No good integer found!" << endl; + else + cout << "Largest good integer is: " << result << endl; + + return 0; +}