From 43b3a8df4c39e7e84c5cdce31b57129b6297bc40 Mon Sep 17 00:00:00 2001 From: SjxSubham Date: Tue, 28 Oct 2025 00:34:33 +0530 Subject: [PATCH] Implement lexGreaterPermutation function --- ...allest Permutation Greater Than Target.cpp | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 3720. Lexicographically Smallest Permutation Greater Than Target.cpp diff --git a/3720. Lexicographically Smallest Permutation Greater Than Target.cpp b/3720. Lexicographically Smallest Permutation Greater Than Target.cpp new file mode 100644 index 0000000..f4122fc --- /dev/null +++ b/3720. Lexicographically Smallest Permutation Greater Than Target.cpp @@ -0,0 +1,47 @@ + // Your code goes here + class Solution { +public: + string lexGreaterPermutation(string s, string target) { + string ans =""; + int n = s.length(); + mapmp; + for(auto&e:s)mp[e]++; + for(int i =0;i m2=mp; + string res =""; + bool ip=1; + for(int j = 0;jfirst; + it->second--; + if(it->second==0)m2.erase(it); + } + else continue; + for(auto&e:m2) + { + while(e.second--)res+=e.first; + } + if(ans =="")ans=res; + else ans = min(ans,res); + } + } + return ans; + } +};