Diagram & Image Explaination🥇 C++ Full Optimized🔥2 PTR | Well Explained
Diagram\n Describe your first thoughts on how to solve this problem. \n\n\n\n# Approach\n Describe your approach to solving the problem. \nint i=0,j=s.length()-
# Diagram\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n![code2flow_Gk6T30 (1).png](https://assets.leetcode.com/users/images/ae1522d1-3dc8-4459-981b-2f2ae9f9a7b2_1684650906.2661316.png)\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nint i=0,j=s.length()-1;: Initialize two variables i and j to the start and end indices of the string respectively.\n\nwhile(i<j): While the indices i and j don\'t cross each other, do the following:\n\nif(s[i]>s[j]): If the character at index i is greater than the character at index j, then replace the character at index i with the character at index j.\n\ns[i]=s[j];\n\nIncrement i and decrement j.\n\ni++;\nj--;\nelse: If the character at index i is less than or equal to the character at index j, then replace the character at index j with the character at index i.\n\ns[j]=s[i];\n\nIncrement i and decrement j.\n\ni++;\nj--;\nreturn s;: Return the modified string.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(N)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n# Code\n```\nclass Solution {\npublic:\n    string makeSmallestPalindrome(string s) {\n        int i=0,j=s.length()-1;\n        while(i<j)\n        {\n            if(s[i]>s[j])\n            {\n                s[i]=s[j];\n                \n                i++;\n                j--;\n            }\n            else\n            {\n                s[j]=s[i];\n                i++;\n                j--;\n            }\n        }return s;\n        \n    }\n};\n```\n![7abc56.jpg](https://assets.leetcode.com/users/images/275376dd-1a0c-4d7a-9d8e-1e79bdf27056_1684651072.6219082.jpeg)\n
['String', 'String Matching', 'C++']