From 7daacfef41499310d605cc2b88879b9e8a990ef2 Mon Sep 17 00:00:00 2001 From: Once-1296 Date: Sun, 19 Oct 2025 11:32:06 +0530 Subject: [PATCH] Added LC 3720 --- ...allest Permutation Greater Than Target.cpp | 48 +++++++++++++++++++ 1 file changed, 48 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..ff27a7e --- /dev/null +++ b/3720. Lexicographically Smallest Permutation Greater Than Target.cpp @@ -0,0 +1,48 @@ +#include +using namespace std; +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; + } +}; \ No newline at end of file