question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
lexicographically-smallest-string-after-operations-with-constraint | Greedy solution (readable code with explanation) | greedy-solution-readable-code-with-expla-krtb | Approach\nTo make the lexicographically smallest string, we spend the cost at leftest character.\n\nFor example, if s = \'cb\', k = 1, we must use this cost at | a127000555 | NORMAL | 2024-04-08T16:42:35.993846+00:00 | 2024-04-08T16:43:33.628481+00:00 | 26 | false | # Approach\nTo make the lexicographically smallest string, we spend the cost at leftest character.\n\nFor example, if `s = \'cb\', k = 1`, we must use this cost at the first character, unless it already becomes to `\'a\'`.\n\nThus, we only need to consider two cases:\n* If there\'s enough k, make character become `\'a\... | 2 | 0 | ['Python3'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | ✅ Java Solution | java-solution-by-harsh__005-avq1 | CODE\nJava []\npublic String getSmallestString(String s, int k) {\n\tStringBuffer res = new StringBuffer("");\n\tchar arr[] = s.toCharArray();\n\tint i=0, n=arr | Harsh__005 | NORMAL | 2024-04-07T04:01:19.538779+00:00 | 2024-04-07T04:01:19.538803+00:00 | 225 | false | ## **CODE**\n```Java []\npublic String getSmallestString(String s, int k) {\n\tStringBuffer res = new StringBuffer("");\n\tchar arr[] = s.toCharArray();\n\tint i=0, n=arr.length;\n\n\twhile(k > 0 && i<n){\n\t\tint id = (arr[i++]-\'a\');\n\t\tint min = Math.min(id, 26-id);\n\n\t\tif(min <= k) {\n\t\t\tres.append(\'a\');... | 2 | 0 | ['Java'] | 1 |
lexicographically-smallest-string-after-operations-with-constraint | Best solution | C++ | Smallest string | best-solution-c-smallest-string-by-nssva-x0om | IntuitionWe need to construct a lexicographically smallest string t such that the cyclic distance between s and t is at most k. This approach ensures that we ob | nssvaishnavi | NORMAL | 2025-02-03T13:06:41.010059+00:00 | 2025-02-03T13:06:41.010059+00:00 | 21 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
We need to construct a lexicographically smallest string t such that the cyclic distance between s and t is at most k. This approach ensures that we obtain the smallest lexicographical string while keeping the distance constraint satisfied.... | 1 | 0 | ['C++'] | 1 |
lexicographically-smallest-string-after-operations-with-constraint | Easy cpp | easy-cpp-by-pb_matrix-2eoy | \nclass Solution {\npublic:\nstring getSmallestString(string s, int k) {\nint n=s.size();\nfor(int j=0;j<n;j++){\n char p=s[j];\n for(char c=\'a\';c<=\'z\';c++) | pb_matrix | NORMAL | 2024-06-10T15:26:07.445035+00:00 | 2024-06-10T15:26:07.445068+00:00 | 1 | false | ```\nclass Solution {\npublic:\nstring getSmallestString(string s, int k) {\nint n=s.size();\nfor(int j=0;j<n;j++){\n char p=s[j];\n for(char c=\'a\';c<=\'z\';c++){\n int x=s[j]-c;\n int yes=min(x,26-x);\n if(k>=yes) \n {s[j]=min(s[j],c),k-=yes; break;}\n}}\nreturn s; }\n};\n``` | 1 | 0 | [] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Greedyyyy, ⌛: O(N) | greedyyyy-on-by-ndr0216-cpwa | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | ndr0216 | NORMAL | 2024-05-29T00:58:33.862218+00:00 | 2024-07-20T02:58:57.616822+00:00 | 4 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(N)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here... | 1 | 0 | ['String', 'Greedy', 'C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Beats 100%🔥|| easy JAVA Solution✅ | beats-100-easy-java-solution-by-priyansh-gbz2 | Code\n\nclass Solution {\n public String getSmallestString(String s, int k) {\n char arr[]=s.toCharArray();\n for(int i=0;i<arr.length;i++){\n | priyanshu1078 | NORMAL | 2024-05-10T18:20:15.017144+00:00 | 2024-05-10T18:20:15.017165+00:00 | 5 | false | # Code\n```\nclass Solution {\n public String getSmallestString(String s, int k) {\n char arr[]=s.toCharArray();\n for(int i=0;i<arr.length;i++){\n Pair x=sol(arr[i],k);\n arr[i]=x.ch;\n k-=x.val;\n if(k==0) break;\n }\n return new String(arr);\... | 1 | 0 | ['Java'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Cleanest Java Code. Only one if-else. Greedy. Simple Intuition. Please Upvote. | cleanest-java-code-only-one-if-else-gree-mr3v | Intuition\n Describe your first thoughts on how to solve this problem. \nGreedy is the way to go.\nMain reason for this is that we want the smalles lexicographi | kod3r | NORMAL | 2024-05-02T06:22:50.375091+00:00 | 2024-05-02T06:24:06.956619+00:00 | 40 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nGreedy is the way to go.\nMain reason for this is that we want the smalles lexicographical string. Therefore we want to invest as much as we can on the earlier letters. \nAs even bzzzz is smaller than caaaa\n\nTry to make every letter sta... | 1 | 0 | ['Java'] | 1 |
lexicographically-smallest-string-after-operations-with-constraint | Simple Greedy Approach with explanation | simple-greedy-approach-with-explanation-l1phl | \n# Approach\n Describe your approach to solving the problem. \nGreedy\n# Complexity\n- Time complexity:O(n)\n Add your time complexity here, e.g. O(n) \n\n- Sp | kmuhammadjon | NORMAL | 2024-04-19T12:12:23.218983+00:00 | 2024-04-19T12:12:23.219005+00:00 | 10 | false | \n# Approach\n<!-- Describe your approach to solving the problem. -->\nGreedy\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nfunc getSmallestString(s string, k int) string {\n... | 1 | 0 | ['String', 'Greedy', 'Go'] | 1 |
lexicographically-smallest-string-after-operations-with-constraint | Beats 96% users... #Quality Code | beats-96-users-quality-code-by-aim_high_-q4us | \n# Code\n\nclass Solution:\n def getSmallestString(self, s: str, k: int) -> str:\n n = len(s)\n t = list(s) # Start with t as a copy of s, we | Aim_High_212 | NORMAL | 2024-04-11T11:38:31.111762+00:00 | 2024-04-11T11:38:31.111780+00:00 | 12 | false | \n# Code\n```\nclass Solution:\n def getSmallestString(self, s: str, k: int) -> str:\n n = len(s)\n t = list(s) # Start with t as a copy of s, we will modify this list in place\n for i in range(n):\n original_char = s[i]\n cost_to_a = min((ord(original_char) - ord(\'a\')) ... | 1 | 0 | ['Python', 'Python3'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | C++ || Easy Strings || ✔✔ | c-easy-strings-by-akanksha984-kuce | Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n) \n\n# Co | akanksha984 | NORMAL | 2024-04-09T07:18:52.982744+00:00 | 2024-04-09T07:18:52.982778+00:00 | 11 | false | # Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n string getSmallestString(string s, int k) {\n for (int i=0; i<s.size(); i++){\n ... | 1 | 0 | ['String', 'Greedy', 'C++'] | 1 |
lexicographically-smallest-string-after-operations-with-constraint | scala | scala-by-len_master-brjo | scala \n def getSmallestString(s: String, k: Int): String = {\n @scala.annotation.tailrec\n def f(ch: List[Char], remaining: Int, acc: List[Char]): List[ | len_master | NORMAL | 2024-04-09T05:14:50.934535+00:00 | 2024-04-09T05:14:50.934565+00:00 | 2 | false | ```scala \n def getSmallestString(s: String, k: Int): String = {\n @scala.annotation.tailrec\n def f(ch: List[Char], remaining: Int, acc: List[Char]): List[Char] = ch match {\n case Nil => acc.reverse\n case head :: tail =>\n val dis = (head - \'a\').min(\'z\' - head + 1)\n if (dis > rema... | 1 | 0 | ['Scala'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | *Iterate and consider 3 cases.. Simple Python solution | iterate-and-consider-3-cases-simple-pyth-myiv | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | yashaswisingh47 | NORMAL | 2024-04-07T13:50:18.176228+00:00 | 2024-04-07T13:50:18.176262+00:00 | 33 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['Python3'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Simple C++ Solution | Linear Time Complexity with constant space | simple-c-solution-linear-time-complexity-7o7v | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | AK200199 | NORMAL | 2024-04-07T12:50:52.492298+00:00 | 2024-04-07T12:50:52.492320+00:00 | 8 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | JAVA MOST OPTIMAL SOLUTION || BEATS 100 % Users || Do UpVote | java-most-optimal-solution-beats-100-use-zlzw | Let\'s first Understand the Problem Statement first : \n\nSince the problem states that find the samllest possible String. \n\n1.Let\'s Understand By an Example | Gourav__5442 | NORMAL | 2024-04-07T12:38:08.073676+00:00 | 2024-04-07T12:38:08.073705+00:00 | 7 | false | # Let\'s first Understand the Problem Statement first : \n\n**Since the problem states that find the samllest possible String.** \n\n**1.Let\'s Understand By an Example what is the smallest String :** \nSuppose we have Two Strings s1 and s2\ns1 = "xawb"\ns2 = "yawb" \n\nsmallest = s1\nHere Both the Strings are similar ... | 1 | 0 | ['Java'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | 6 Liner Solution || Very Easy || Python3 | 6-liner-solution-very-easy-python3-by-ya-4fee | Time Complexity:- O(n)\n\nSpace Complexity:- O(n)\n\nExplanation of my code:\n\n=> Initialize an empty string \'res\' to store the result.\n\n=> Iterate through | YangZen09 | NORMAL | 2024-04-07T08:16:00.195733+00:00 | 2024-04-07T08:16:00.195767+00:00 | 94 | false | **Time Complexity:-** *O(n)*\n\n**Space Complexity:-** *O(n)*\n\n**Explanation of my code:**\n\n**=>** *Initialize an empty string \'res\' to store the result.*\n\n**=>** *Iterate through each character in the input string \'s\'.*\n\n**=>** *For each character, calculate the minimum distance to reach \'a\' or \'z\' fro... | 1 | 0 | ['String', 'Python3'] | 3 |
lexicographically-smallest-string-after-operations-with-constraint | Python Solution | python-solution-by-shoo-lin-6s31 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Shoo-lin | NORMAL | 2024-04-07T06:49:22.244799+00:00 | 2024-04-07T06:49:22.244826+00:00 | 11 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution:\n def getSmallestString(self, s: str, k: int) -> str:\n\n ... | 1 | 0 | ['Python3'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | easy python solution | easy-python-solution-by-prashasst-gh88 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | prashasst | NORMAL | 2024-04-07T06:00:25.384233+00:00 | 2024-04-07T06:00:25.384263+00:00 | 6 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['Python3'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Easy python | easy-python-by-ekambareswar1729-s86w | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | ekambareswar1729 | NORMAL | 2024-04-07T05:48:34.955037+00:00 | 2024-04-07T05:48:34.955063+00:00 | 8 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['Python3'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | JS - Simple O(n) Solution | js-simple-on-solution-by-e4truong-ell9 | Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(1)\n\n# Code\n\n/**\n * @param {string} s\n * @param {number} k\n * @return {string}\n */\nvar getS | e4truong | NORMAL | 2024-04-07T04:50:05.556141+00:00 | 2024-04-07T04:50:05.556159+00:00 | 45 | false | # Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(1)\n\n# Code\n```\n/**\n * @param {string} s\n * @param {number} k\n * @return {string}\n */\nvar getSmallestString = function (s, k) {\n const str = s.split("");\n\n for (let i = 0; i < str.length && k >= 0; i++) {\n const distanceFromA = str[... | 1 | 0 | ['Greedy', 'JavaScript'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | ✅ My Well Commented C++ Solution || Beats 100% C++ of users || Easy to Understand | my-well-commented-c-solution-beats-100-c-hyrz | Intuition\nWhen I first encountered this problem, I thought of weather to go to the right side of the current character or left side. and then to know weather t | NachiketGavad | NORMAL | 2024-04-07T04:47:40.473690+00:00 | 2024-04-07T05:07:33.365258+00:00 | 97 | false | # Intuition\nWhen I first encountered this problem, I thought of weather to go to the right side of the current character or left side. and then to know weather to perform which operation for each character, based on the low cost to perform that operation on every character.\n\n# Approach \nI iterated through each char... | 1 | 0 | ['C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | [ Swift ] O(n) solution | swift-on-solution-by-icedcappuccino-nde0 | Intuition\nLexicographical order of s string is determined by the letters from left to right.\n\nTherefore, we should prioritize making each letter in the strin | icedcappuccino | NORMAL | 2024-04-07T04:46:10.960467+00:00 | 2024-04-07T04:50:09.551855+00:00 | 11 | false | # Intuition\nLexicographical order of s string is determined by the letters from left to right.\n\nTherefore, we should prioritize making each letter in the string as lexographically small as possible, starting from the left.\n\n# Complexity\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(1)$$, excluding the spac... | 1 | 0 | ['Greedy', 'Swift'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | 🔥Beats 100% - O(n) - Easiest Approach | Clean Code | C++ | | beats-100-on-easiest-approach-clean-code-d27e | Code\n\nclass Solution {\npublic:\n string getSmallestString(string s, int k) {\n for (int i = 0; i < s.size(); i++) \n {\n \n | Antim_Sankalp | NORMAL | 2024-04-07T04:20:08.786939+00:00 | 2024-04-07T04:20:08.786958+00:00 | 58 | false | # Code\n```\nclass Solution {\npublic:\n string getSmallestString(string s, int k) {\n for (int i = 0; i < s.size(); i++) \n {\n \n if (s[i] == \'a\')\n continue;\n\n int distanceToA = s[i] - \'a\';\n int cyclicDistanceToA = min(distanceToA, 26... | 1 | 0 | ['C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Easy To Understand | easy-to-understand-by-ad18-06rm | Approach\n- Create a string of size N contanining only \'a\', Because we need Lexicographical String.\n- calculate the cyclic distance, check :- \n1. If less th | AD18 | NORMAL | 2024-04-07T04:11:16.744751+00:00 | 2024-04-07T04:11:16.744769+00:00 | 23 | false | # Approach\n- Create a string of size N contanining only \'a\', Because we need Lexicographical String.\n- calculate the cyclic distance, check :- \n1. If less than k, may that character remain same (i.e,\'a\').\n2. else if(k>0) then choose the character, which has distance equal to k.\n3. else make remaining character... | 1 | 0 | ['C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Cpp | cpp-by-laxsingh9659-in09 | Complexity\n- Time complexity: O(n*26)\n Add your time complexity here, e.g. O(n) \n\n\n# Code\n\nclass Solution {\npublic:\n string getSmallestString(string | LaxmanSinghBisht | NORMAL | 2024-04-07T04:10:32.095584+00:00 | 2024-04-07T04:11:20.706772+00:00 | 30 | false | # Complexity\n- Time complexity: O(n*26)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n\n# Code\n```\nclass Solution {\npublic:\n string getSmallestString(string s, int ki) {\n string ans="";\n for(int i=0;i<s.length();i++){\n bool flag=true;\n for(int k=0;k<26;k++){\n... | 1 | 0 | ['C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | O(n) Time O(1) Space, Simplest | on-time-o1-space-simplest-by-ayunick-k6xr | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | ayunick | NORMAL | 2024-04-07T04:07:42.724389+00:00 | 2024-04-07T04:08:52.547809+00:00 | 34 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['Greedy', 'C++'] | 1 |
lexicographically-smallest-string-after-operations-with-constraint | Straightforward simple one pass Java solution | O(n) | straightforward-simple-one-pass-java-sol-pphc | Intuition\nOur goal is to 1st make each character \'a\', else decrement to whatever is the least possible character.\n\n Describe your first thoughts on how to | shashankbhat | NORMAL | 2024-04-07T04:06:21.294039+00:00 | 2024-04-07T04:06:21.294070+00:00 | 50 | false | # Intuition\nOur goal is to 1st make each character \'a\', else decrement to whatever is the least possible character.\n\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nWe have 2 conditions to check:\n1. If incrementing characters upto k times can get us \'a\'.\n2. If decrementing ch... | 1 | 0 | ['String', 'Java'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Java/Python Clean Solution | javapython-clean-solution-by-shree_govin-pirj | Complexity\n- Time complexity:O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(n)\n Add your space complexity here, e.g. O(n) \n\n# Code | Shree_Govind_Jee | NORMAL | 2024-04-07T04:04:02.966372+00:00 | 2024-04-07T04:04:02.966395+00:00 | 133 | false | # Complexity\n- Time complexity:$$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n**Java**\n```\nclass Solution {\n \n private int helper(char ch){\n return Math.min(ch-\'a\', 26-(ch-\'a\'));\n ... | 1 | 0 | ['Array', 'String', 'String Matching', 'Java', 'Python3'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | ✅C++ Accepted | Greedy | O(26*n)⛳ | c-accepted-greedy-o26n-by-manii15-ntpt | \n# Code\n\nclass Solution {\npublic:\n string getSmallestString(string s, int k) {\n string res = "";\n \n map<char,pair<int,int>> mp;\ | manii15 | NORMAL | 2024-04-07T04:03:54.883998+00:00 | 2024-04-07T04:03:54.884020+00:00 | 13 | false | \n# Code\n```\nclass Solution {\npublic:\n string getSmallestString(string s, int k) {\n string res = "";\n \n map<char,pair<int,int>> mp;\n for(int i=1;i<=26;i++){\n mp[\'a\'+i-1] = {i,i+26};\n }\n \n for(int i=0;i<s.size();i++){\n for(char c = ... | 1 | 0 | ['C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | My Contest Solution | my-contest-solution-by-spravinkumar9952-07xc | \n# Code\n\nclass Solution {\npublic:\n \n int dist(char a, char b){\n int may1 = abs(b-a);\n int may2 = 26 - may1;\n return min(may1 | spravinkumar9952 | NORMAL | 2024-04-07T04:03:48.755877+00:00 | 2024-04-07T04:03:48.755897+00:00 | 40 | false | \n# Code\n```\nclass Solution {\npublic:\n \n int dist(char a, char b){\n int may1 = abs(b-a);\n int may2 = 26 - may1;\n return min(may1, may2);\n }\n \n \n string getSmallestString(string s, int k) {\n \n for(char &c : s){\n int d = dist(c, \'a\');\n ... | 1 | 0 | ['C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Easy solution in C++ | easy-solution-in-c-by-bug-setter-cy8s | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | bug-setter | NORMAL | 2024-04-07T04:02:57.184169+00:00 | 2024-04-07T04:02:57.184193+00:00 | 12 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Simple Recursion 🔥🔥 | simple-recursion-by-vritant-goyal-np9d | Code\n\nclass Solution {\n public int findans(char first,char last){\n int diff1 = first-last;\n int diff2=last-first;\n if (diff1 < 0)d | vritant-goyal | NORMAL | 2024-04-07T04:02:17.705529+00:00 | 2024-04-07T04:05:57.029452+00:00 | 13 | false | # Code\n```\nclass Solution {\n public int findans(char first,char last){\n int diff1 = first-last;\n int diff2=last-first;\n if (diff1 < 0)diff1 += 26;\n if(diff2<0)diff2+=26;\n return Math.min(diff1,diff2);\n }\n public String helper(String s,int k,int ind){\n if(ind... | 1 | 0 | ['Java'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | 3106. Lexicographically Smallest String After Operations With Constraint | Adhoc | Strings | 3106-lexicographically-smallest-string-a-myk8 | 🧠 # IntuitionOkay, so you’re handed a string s, and you’re allowed to reduce the characters in it to make it lexicographically smaller. But—there’s a catch—you | Shingini | NORMAL | 2025-04-11T10:41:05.766717+00:00 | 2025-04-11T10:41:05.766717+00:00 | 1 | false |
### 🧠 # Intuition
Okay, so you’re handed a string `s`, and you’re allowed to **reduce the characters** in it to make it lexicographically smaller. But—there’s a catch—you can only **spend `k` units total**.
Each character can only be reduced *towards* `'a'` by using your `k` points. For example:
- `'d' -> 'a'` co... | 0 | 0 | ['C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | C++ greedy string | c-greedy-string-by-czxoxo-95c1 | Make this faster by doing it in place. Greedily increment with a budget (in this case the "distance").Code | czxoxo | NORMAL | 2025-03-27T20:06:10.309976+00:00 | 2025-03-27T20:06:10.309976+00:00 | 2 | false | Make this faster by doing it in place. Greedily increment with a budget (in this case the "distance").
# Code
```cpp []
class Solution {
public:
string getSmallestString(string s, int k) {
// this means, throughout this string we need to find the letter that can substitute the letter in the orig... | 0 | 0 | ['C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Python3 - simple O(n) solution | python3-simple-on-solution-by-saitama1v1-e7xl | Complexity
Time complexity:
O(n)
Space complexity:
O(n)
Code | saitama1v1 | NORMAL | 2025-02-16T16:11:47.255606+00:00 | 2025-02-16T16:16:12.255388+00:00 | 4 | false | # Complexity
- Time complexity:
O(n)
- Space complexity:
O(n)
# Code
```python3 []
class Solution:
def getSmallestString(self, s: str, k: int) -> str:
if k == 0:
return s
a = "abcdefghijklmnopqrstuvwxyz"
res = ""
for l in s:
if k <= 0 or l == 'a':
... | 0 | 0 | ['Python3'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Easy Solution Using Greedy. | easy-solution-using-greedy-by-akshatuke-0ct2 | Code | AkshatUke | NORMAL | 2025-02-08T18:15:14.739177+00:00 | 2025-02-08T18:15:14.739177+00:00 | 3 | false |
# Code
```java []
class Solution {
public String getSmallestString(String s, int k) {
String ans = "";
int i = 0;
for(i = 0;i < s.length();i++) {
int x = s.charAt(i)-'a';
if(26 - x < x) {
x = 26-x;
}
if(k >= x) {
... | 0 | 0 | ['String', 'Greedy', 'Java'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | (Beats 100% python) Why do you ask me to do unnecessary things? | why-do-you-ask-me-to-do-unnecessary-thin-m15o | IntuitionDefinitely a medium problem. Had to rack my brain for how to represent the cyclic distance efficiently, without using something like a circular buffer | Alex_Tilson | NORMAL | 2025-02-04T01:28:15.543856+00:00 | 2025-02-04T01:32:34.248540+00:00 | 2 | false | # Intuition
Definitely a medium problem. Had to rack my brain for how to represent the cyclic distance efficiently, without using something like a circular buffer of length 26.
Most importantly, there is always a '$$center$$' character that actually changes to anything other than an 'a'. If I could figure out what and... | 0 | 0 | ['Python'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Easy Solution | easy-solution-by-muskan_kutiyal-oxdj | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Muskan_Kutiyal | NORMAL | 2025-02-03T13:14:24.351706+00:00 | 2025-02-03T13:14:24.351706+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['JavaScript'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | StringBuilder to track return string, loop chars to check if it can be changed lower | stringbuilder-to-track-return-string-loo-jw4i | IntuitionApproachComplexity
Time complexity:
O(N)
Space complexity:
O(N)Code | linda2024 | NORMAL | 2025-01-29T22:52:01.502610+00:00 | 2025-01-29T22:52:01.502610+00:00 | 5 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(N)
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(N)
... | 0 | 0 | ['C#'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | [JavaScript] Easy solution | javascript-easy-solution-by-liew-li-mgb4 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | liew-li | NORMAL | 2025-01-28T04:28:39.067075+00:00 | 2025-01-28T04:28:39.067075+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['JavaScript'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | 3106. Lexicographically Smallest String After Operations With Constraint | 3106-lexicographically-smallest-string-a-jfgd | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | G8xd0QPqTy | NORMAL | 2025-01-22T08:01:38.107673+00:00 | 2025-01-22T08:01:38.107673+00:00 | 1 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['Dart'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Python O(n) Solution with Code Comments | python-on-solution-with-code-comments-by-ki9q | Complexity
Time complexity: O(n)
Space complexity: O(n) - returning string.
Code | William_Pattison | NORMAL | 2025-01-11T19:56:30.254844+00:00 | 2025-01-11T19:56:30.254844+00:00 | 3 | false | # Complexity
- Time complexity: O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: O(n) - returning string.
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```python3 []
class Solution:
def getSmallestString(self, s: str, k: int) -> str:
answer = ""
for i ... | 0 | 0 | ['Python3'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | SIMPLE ONE PASS SOLUTION | simple-one-pass-solution-by-mohit_kukrej-keo1 | Complexity
Time complexity: O(n)
Code | Mohit_kukreja | NORMAL | 2025-01-08T06:37:13.415335+00:00 | 2025-01-08T06:37:13.415335+00:00 | 4 | false | # Complexity
- Time complexity: O(n)
# Code
```cpp []
class Solution {
public:
string getSmallestString(string s, int k) {
int n = s.size();
for(auto &i: s){
int back = i - 'a';
int front = ('a' - i + 26) % 26;
if(front <= back && front <= k){
k ... | 0 | 0 | ['C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | [Java] ✅ 1MS ✅ 100% ✅ FASTEST ✅ BEST ✅ CLEAN CODE | java-1ms-100-fastest-best-clean-code-by-ud0fw | Approach\n1. The smallest lexic string starts with lowest chars (a) first\n2. Apply a greedy algorithm, trying to lower the first chars while k allows it.\n3. T | StefanelStan | NORMAL | 2024-12-01T00:44:43.211777+00:00 | 2024-12-01T00:44:43.211804+00:00 | 2 | false | # Approach\n1. The smallest lexic string starts with lowest chars (a) first\n2. Apply a greedy algorithm, trying to lower the first chars while k allows it.\n3. Traverse from first :\n - if k == 0, then you cannot do any modification; append the current letter as it is\n - else, figure out the min distance from c... | 0 | 0 | ['Java'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | C++ Seriously faster and simpler than all other solutions | c-seriously-faster-and-simpler-than-all-2uk4i | Thoughts\n\nWhile writing the code I was thinking about what makes fast code:\n- Solve as much as you can at compile time (not runtime)\n- Minimize branching\n | atspam | NORMAL | 2024-11-17T06:26:50.211075+00:00 | 2024-11-17T06:26:50.211097+00:00 | 6 | false | # Thoughts\n\nWhile writing the code I was thinking about what makes fast code:\n- Solve as much as you can at compile time (not runtime)\n- Minimize branching\n - maximize predictive branching\n- Minimize expensive computations\n\nThese points helped me craft the answer and I think it led to more intuitive code. The ... | 0 | 0 | ['C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | C# Solution || Easy Solution | c-solution-easy-solution-by-mohamedabdel-jviv | csharp []\npublic class Solution {\n public string GetSmallestString(string s, int k) {\n var arr = s.ToCharArray();\n for(int i = 0;i < arr.Le | mohamedAbdelety | NORMAL | 2024-11-11T17:45:54.221627+00:00 | 2024-11-11T17:45:54.221660+00:00 | 3 | false | ```csharp []\npublic class Solution {\n public string GetSmallestString(string s, int k) {\n var arr = s.ToCharArray();\n for(int i = 0;i < arr.Length && k > 0;i++){\n int diff = arr[i] - \'a\';\n int opDiff = 26 - diff;\n if(opDiff < diff && opDiff <= k){\n ... | 0 | 0 | ['C#'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Simple C++ | Easy to understand | Beats 100% | simple-c-easy-to-understand-beats-100-by-q9ca | Approach\nSince, we want to get the lexicograpically sorted, we can think of greedy approach of trying to keep the initial characters smaller. \n\n# Complexity\ | kapiswayatul | NORMAL | 2024-11-07T20:35:44.952142+00:00 | 2024-11-07T20:35:44.952176+00:00 | 3 | false | # Approach\nSince, we want to get the lexicograpically sorted, we can think of greedy approach of trying to keep the initial characters smaller. \n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n string getSmallestString(string s, int k) {\n ... | 0 | 0 | ['C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | C++ greedy | c-greedy-by-the_ghuly-81rs | Code\ncpp []\nclass Solution {\npublic:\n string getSmallestString(string s, int k) {\n for(int i = 0;k && i<s.size();++i)\n {\n int | the_ghuly | NORMAL | 2024-10-29T07:39:02.668847+00:00 | 2024-10-29T07:39:02.668876+00:00 | 1 | false | # Code\n```cpp []\nclass Solution {\npublic:\n string getSmallestString(string s, int k) {\n for(int i = 0;k && i<s.size();++i)\n {\n int dist = min(s[i]-\'a\',26-s[i]+\'a\');\n if(dist>k)\n {\n s[i]-=k;\n return s;\n }\n ... | 0 | 0 | ['C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Python3 || O(n) || 3ms beats 100% | python3-on-3ms-beats-100-by-stygian84-a69j | Intuition\n- Check the steps needed to get each letter to a starting from left\n- At each iteration, reduce k by no. of steps\n- If no. of steps>=k, then we red | stygian84 | NORMAL | 2024-10-24T08:54:12.857179+00:00 | 2024-10-24T08:54:12.857214+00:00 | 1 | false | # Intuition\n- Check the steps needed to get each letter to ```a``` starting from left\n- At each iteration, reduce ```k``` by no. of steps\n- If no. of steps>=k, then we reduce the letter by ```k``` steps and terminate the loop. \n\n# Complexity\n- Time complexity: O(n)\n\n# Code\n```python3 []\nclass Solution:\n d... | 0 | 0 | ['Python3'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Beats 100% Solutions. Python Greedy Solution. | beats-100-solutions-python-greedy-soluti-t3hx | idea: if k > len(s) * 26, means we got more than enough k, so return "a" * len(s)\n # if not, make a res string first\n # now iterate the string, | wasiflatifhussain | NORMAL | 2024-09-16T15:11:16.097993+00:00 | 2024-09-16T15:11:16.098024+00:00 | 0 | false | # idea: if k > len(s) * 26, means we got more than enough k, so return "a" * len(s)\n # if not, make a res string first\n # now iterate the string, and for each char, check distance to get to "a" in both forward and backward \n # direction, as it is CYCLIC\n # now if distForward <= distBackw... | 0 | 0 | ['Python3'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Python 3, Beats 98%, One pass, Greedy | python-3-beats-98-one-pass-greedy-by-roh-n25c | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | rohanchoudhary2000 | NORMAL | 2024-09-09T19:31:25.728094+00:00 | 2024-09-09T19:31:25.728111+00:00 | 1 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['String', 'Greedy', 'Python3'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Easy to understand, explained solution || Python | easy-to-understand-explained-solution-py-2iui | Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n\n# Co | georges_dib | NORMAL | 2024-08-31T16:21:57.957228+00:00 | 2024-08-31T16:21:57.957258+00:00 | 0 | false | # Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nclass Solution:\n def getSmallestString(self, s: str, k: int) -> str: \n s = list(s)\n for i ... | 0 | 0 | ['Python3'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Greedily try all possible differences | greedily-try-all-possible-differences-by-dk4g | Approach\n Greedy Approach\n\n# Intuition \nSee, we need to make the smallest lexicographical string right? which means the characters from beginning must be a | hokteyash | NORMAL | 2024-08-19T09:02:57.427787+00:00 | 2024-08-19T10:28:11.155163+00:00 | 4 | false | # Approach\n Greedy Approach\n\n# Intuition \nSee, we need to make the smallest lexicographical string right? which means the characters from beginning must be as minimal or smaller as possible by taking care of k value as well.\n\nRight? It means the character from beginning must be starts with something similar to t... | 0 | 0 | ['String', 'Greedy', 'Java'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Easy CPP Solution | easy-cpp-solution-by-clary_shadowhunters-2fna | \n# Code\n\nclass Solution {\npublic:\n string getSmallestString(string s, int k) {\n string ans="";\n int cur=0;\n int i=0;\n fo | Clary_ShadowHunters | NORMAL | 2024-08-15T10:22:29.275407+00:00 | 2024-08-15T10:22:29.275434+00:00 | 4 | false | \n# Code\n```\nclass Solution {\npublic:\n string getSmallestString(string s, int k) {\n string ans="";\n int cur=0;\n int i=0;\n for (i=0;i<s.size();i++)\n {\n for (int ch=\'a\';ch<=s[i];ch++)\n {\n int diff=abs(s[i]-ch);\n diff=... | 0 | 0 | ['C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Java - Circular arrangement of letters | java-circular-arrangement-of-letters-by-p59ej | Intuition\n Describe your first thoughts on how to solve this problem. \nIt is clear as soon as the problem is seen that each character has to be calculated unt | sm_19 | NORMAL | 2024-08-05T02:44:39.868692+00:00 | 2024-08-05T02:44:39.868722+00:00 | 1 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIt is clear as soon as the problem is seen that each character has to be calculated until the \'k\' is totally used up. So, for each character the smallest possible character within \'k\' distance has to be found.\n# Approach\n<!-- Descri... | 0 | 0 | ['Java'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Java Greedy soln | java-greedy-soln-by-vharshal1994-rmor | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | vharshal1994 | NORMAL | 2024-08-04T13:17:54.280795+00:00 | 2024-08-04T13:17:54.280824+00:00 | 0 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Java'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | EASY beat 100% JAVA C++ | easy-beat-100-java-c-by-vivek__kumar__09-wfek | Intuition\nput a as times as possible.\n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space comp | vivek4565 | NORMAL | 2024-08-03T18:17:20.089015+00:00 | 2024-08-03T18:17:20.089042+00:00 | 3 | false | # Intuition\nput a as times as possible.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\n public int dist(char ch){\n return Math.min(26-Math.abs(ch-\'a\'),Math.abs(\'a\'-ch));\n ... | 0 | 0 | ['Greedy', 'C++', 'Java', 'Python3'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | C++ solution | c-solution-by-oleksam-hufx | \n// Please, upvote if you like it. Thanks :-)\nstring getSmallestString(string s, int k) {\n\tint n = s.size();\n\tfor (int i = 0; i < n & k > 0; i++) {\n\t\ti | oleksam | NORMAL | 2024-08-01T18:46:08.246118+00:00 | 2024-08-01T18:46:08.246145+00:00 | 0 | false | ```\n// Please, upvote if you like it. Thanks :-)\nstring getSmallestString(string s, int k) {\n\tint n = s.size();\n\tfor (int i = 0; i < n & k > 0; i++) {\n\t\tint dist = min(s[i] - \'a\', \'z\' - s[i] + 1);\n\t\ts[i] = (dist <= k ? \'a\' : s[i] - k);\n\t\tk -= dist;\n\t}\n\treturn s;\n}\n``` | 0 | 0 | ['Greedy', 'C', 'C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | ✅Easy and Simple ✅Clean Code | easy-and-simple-clean-code-by-ayushluthr-7wz9 | Guy\'s if you find this solution helpful \uD83D\uDE0A, PLEASE do UPVOTE. By doing that it motivate\'s me to create more better post like this \u270D\uFE0F\nFoll | ayushluthra62 | NORMAL | 2024-07-26T20:03:29.188807+00:00 | 2024-07-26T20:03:29.188833+00:00 | 2 | false | ***Guy\'s if you find this solution helpful \uD83D\uDE0A, PLEASE do UPVOTE. By doing that it motivate\'s me to create more better post like this \u270D\uFE0F***<br>\n**Follow me on LinkeDin [[click Here](https://www.linkedin.com/in/ayushluthra62/)]**\n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(1... | 0 | 0 | ['String', 'Greedy', 'C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Golang simple O(n) solution | golang-simple-on-solution-by-tjucoder-46ep | Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\ngo\nfunc getSmallestString(s string, k int) string {\n\t// abcdefghijklm\n\t// nopq | tjucoder | NORMAL | 2024-07-22T13:11:15.815854+00:00 | 2024-07-22T13:11:15.815874+00:00 | 0 | false | # Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n```go\nfunc getSmallestString(s string, k int) string {\n\t// abcdefghijklm\n\t// nopqrstuvwxyz\n\tsb := strings.Builder{}\n\tfor _, v := range s {\n\t\tif k == 0 {\n\t\t\tsb.WriteRune(v)\n continue\n\t\t}\n\t\tstep2a := 0... | 0 | 0 | ['Go'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | EASY C++ || GREEDY || STRING | easy-c-greedy-string-by-sanskarkumar028-hslj | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | sanskarkumar028 | NORMAL | 2024-07-19T17:33:52.804502+00:00 | 2024-07-19T17:33:52.804536+00:00 | 0 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['String', 'Greedy', 'C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Java | O(n) | Greedy check both direction | Easy with comments | java-on-greedy-check-both-direction-easy-29cz | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | meltawab | NORMAL | 2024-07-10T20:04:21.365782+00:00 | 2024-07-10T20:04:21.365813+00:00 | 0 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Java'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Simple O(N) TC and SC solution | simple-on-tc-and-sc-solution-by-batmansa-0mox | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | batmansachin | NORMAL | 2024-06-23T13:51:56.432652+00:00 | 2024-06-23T13:51:56.432678+00:00 | 0 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $... | 0 | 0 | ['Java'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Beats 100% simple iteration through string | beats-100-simple-iteration-through-strin-7grl | Intuition\n Describe your first thoughts on how to solve this problem. \n1. Initialization:\nDetermine the length n of the string s.\nIf k is zero, return the o | saurabh0047 | NORMAL | 2024-06-15T10:42:49.247857+00:00 | 2024-06-15T10:42:49.247894+00:00 | 2 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n1. Initialization:\nDetermine the length n of the string s.\nIf k is zero, return the original string as no operations are allowed.\n\n2. Iterate Over the String:\nLoop through each character in the string from left to right. The earlier ... | 0 | 0 | ['C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | [C++] Greedy | c-greedy-by-ericyxing-ttdq | Code\n\nclass Solution {\npublic:\n string getSmallestString(string s, int k) {\n string ans = s;\n int n = s.size(), i = 0;\n while (k | EricYXing | NORMAL | 2024-06-11T05:33:03.936867+00:00 | 2024-06-11T05:33:03.936902+00:00 | 2 | false | # Code\n```\nclass Solution {\npublic:\n string getSmallestString(string s, int k) {\n string ans = s;\n int n = s.size(), i = 0;\n while (k > 0 && i < n)\n {\n int d = min(s[i] - \'a\', \'z\' - s[i] + 1);\n if (k > d)\n {\n ans[i] = \'a\';\... | 0 | 0 | ['Greedy', 'C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | simple if else | simple-if-else-by-sumit1906-04wu | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | sumit1906 | NORMAL | 2024-06-07T04:22:20.943647+00:00 | 2024-06-07T04:22:20.943686+00:00 | 0 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(N)\n\n- Space complexity: O(1)\n\n# Code\n```\nclass Solution {\npublic:\n string getSmallestString(string s, int k) \n {\n ... | 0 | 0 | ['C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Simple Java Solution | simple-java-solution-by-vansh_goel-e894 | Beats 100%\n\n# Code\n\nclass Solution {\n public String getSmallestString(String s, int k) {\n if(k==0) return s;\n StringBuilder sb=new Strin | vg_85 | NORMAL | 2024-06-04T18:16:32.063828+00:00 | 2024-06-04T18:16:32.063856+00:00 | 5 | false | Beats 100%\n\n# Code\n```\nclass Solution {\n public String getSmallestString(String s, int k) {\n if(k==0) return s;\n StringBuilder sb=new StringBuilder();\n int i=0;\n for(i=0;i<s.length();i++){\n if(k==0) break;\n int c=s.charAt(i)-\'a\';\n if(c>13) c=... | 0 | 0 | ['String', 'Java'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | C++ || EASY CLEAN || SHORT CODE | c-easy-clean-short-code-by-gauravgeekp-8dre | \n\n# Code\n\nclass Solution {\npublic:\n string getSmallestString(string s, int k) {\n int n=s.size(),c=0;\n string f=s;\n for(int i=0; | Gauravgeekp | NORMAL | 2024-06-03T23:04:41.709336+00:00 | 2024-06-03T23:04:41.709359+00:00 | 2 | false | \n\n# Code\n```\nclass Solution {\npublic:\n string getSmallestString(string s, int k) {\n int n=s.size(),c=0;\n string f=s;\n for(int i=0;i<n;i++)\n {\n for(char g=\'a\';g<=\'z\';g++)\n {\n int m=min(abs(g-s[i]),26-abs(g-s[i]));\n if(m+... | 0 | 0 | ['C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Simple Solution | simple-solution-by-chris1337-u1z9 | \n# Code\n\n# @param {String} s\n# @param {Integer} k\n# @return {String}\ndef get_smallest_string(s, k)\n hash = {}\n # Dump the alphabet into an array.\ | Chris1337 | NORMAL | 2024-06-03T22:33:16.808707+00:00 | 2024-06-03T22:33:16.808732+00:00 | 1 | false | \n# Code\n```\n# @param {String} s\n# @param {Integer} k\n# @return {String}\ndef get_smallest_string(s, k)\n hash = {}\n # Dump the alphabet into an array.\n alphabet = ("a".."z").to_a\n\n # Create a hash mapping all \n # letters of the alphabet to the\n # shortest distance to "a"\n dist = 0\n ... | 0 | 0 | ['Ruby'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Easy solution with php | easy-solution-with-php-by-husniddinuz-ij6m | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Husniddinuz | NORMAL | 2024-05-29T09:43:52.544694+00:00 | 2024-05-29T09:43:52.544723+00:00 | 1 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['PHP'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Python3. Greedily force "a" at start | python3-greedily-force-a-at-start-by-nik-vf5x | Intuition\nSeems like need to greedily set the first letter to "a" or the lowest possible, then the second letter etc.\n\n# Approach\nGo letter by letter, pick | nikamir | NORMAL | 2024-05-27T23:20:56.129080+00:00 | 2024-05-27T23:20:56.129098+00:00 | 1 | false | # Intuition\nSeems like need to greedily set the first letter to "a" or the lowest possible, then the second letter etc.\n\n# Approach\nGo letter by letter, pick the minimal cost of changing to "a" or the lowest possible letter.\n\n# Complexity\n- Time complexity:\n$$O(n)$$, scan the string\n\n- Space complexity:\n$$O(... | 0 | 0 | ['Python3'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | lexicographically-smallest-string-after-operations-with-constraint | lexicographically-smallest-string-after-6eh2f | Intuition\nIt is brute force approach to check\nif it is possible to get \'a\' from either left or right side\nChoose the min side\n# Approach\nAlways try to ge | sai_teja13 | NORMAL | 2024-05-26T00:04:46.566091+00:00 | 2024-05-26T00:06:33.913443+00:00 | 1 | false | # Intuition\nIt is brute force approach to check\nif it is possible to get \'a\' from either left or right side\nChoose the min side\n# Approach\nAlways try to get \'a\' because we need lexicographically-smallest-string\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n# Code\n```\nclass Solution:\n... | 0 | 0 | ['Python3'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | [C++] Greedy Solution | c-greedy-solution-by-quater_nion-h844 | Intuition\nCyclic distance between two characters = min((b-a+26)%26, (a-b+26)%26)\nIterate through all the characters from left to right. If we have enough K le | quater_nion | NORMAL | 2024-05-22T17:16:15.825181+00:00 | 2024-05-22T17:50:30.793958+00:00 | 0 | false | # Intuition\nCyclic distance between two characters = `min((b-a+26)%26, (a-b+26)%26)`\nIterate through all the characters from left to right. If we have enough K left to make the character to make the character \'a\', then make it while decreasing k accordingly. Else decrease the character as much as possible with the ... | 0 | 0 | ['Greedy', 'C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Easily understandable O(n) solution | easily-understandable-on-solution-by-vis-w3ms | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | vishwasrajbatham151 | NORMAL | 2024-05-22T02:53:48.430596+00:00 | 2024-05-22T02:53:48.430623+00:00 | 0 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $... | 0 | 0 | ['C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | simple if else statements || Beats 97 || o(n) || | simple-if-else-statements-beats-97-on-by-4160 | \n\n# Code\n\nclass Solution:\n def getSmallestString(self, s: str, k: int) -> str:\n res=""\n for i in s:\n minimumDistance=min(ord | sumanth2328 | NORMAL | 2024-05-19T21:19:18.799656+00:00 | 2024-05-19T21:19:18.799673+00:00 | 1 | false | \n\n# Code\n```\nclass Solution:\n def getSmallestString(self, s: str, k: int) -> str:\n res=""\n for i in s:\n minimumDistance=min(ord("z")-ord(i)+1,ord(i)-ord("a"))\n if i=="a":\n res+="a"\n elif minimumDistance<k+1:\n res+="a"\n ... | 0 | 0 | ['String', 'Greedy', 'Python3'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Best Most Optimal Clean Code | best-most-optimal-clean-code-by-f2017164-zsjt | Intuition\n Describe your first thoughts on how to solve this problem. \nThink Greedy\n# Approach\n Describe your approach to solving the problem. \nStarting fr | f20171647 | NORMAL | 2024-05-18T20:01:09.381441+00:00 | 2024-05-18T20:01:09.381476+00:00 | 0 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThink Greedy\n# Approach\n<!-- Describe your approach to solving the problem. -->\nStarting from the left, try all 26 characters within the distance k, return t when k is exhausted\n# Complexity\n- Time complexity:\n<!-- Add your time com... | 0 | 0 | ['C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Intuitive Java Solution | intuitive-java-solution-by-bapatanuparth-k6q1 | Intuition\n Describe your first thoughts on how to solve this problem. \n- To get lexicographically smallest, firstly make as many characters == \'a\' as possib | bapatanuparth | NORMAL | 2024-05-16T18:41:34.368811+00:00 | 2024-05-16T18:41:34.368835+00:00 | 5 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- To get lexicographically smallest, firstly make as many characters == \'a\' as possible from left of the string. Then if we dont have enough \'k\' to reach \'a\', then reach the lowest possible character by utilizing all the \'k\' on th... | 0 | 0 | ['Java'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Java | String builder Simple solution | java-string-builder-simple-solution-by-s-qhwh | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | sheerapthinath | NORMAL | 2024-05-14T02:32:50.473505+00:00 | 2024-05-14T02:32:50.473536+00:00 | 6 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['Java'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | greedy move from index 0 to n-1 || easy to understand || must see | greedy-move-from-index-0-to-n-1-easy-to-f1n00 | Code\n\nclass Solution {\npublic:\n string getSmallestString(string s, int k) {\n \n int dis = 0;\n if(k == 0) return s;\n | akshat0610 | NORMAL | 2024-05-12T17:34:37.038989+00:00 | 2024-05-12T17:34:37.039020+00:00 | 1 | false | # Code\n```\nclass Solution {\npublic:\n string getSmallestString(string s, int k) {\n \n int dis = 0;\n if(k == 0) return s;\n string ans = s;\n for(int i = 0 ; i < s.length() ; i++){\n if(dis == k) return ans;\n if(s[i] == \'a\') continue;\n ... | 0 | 0 | ['String', 'Greedy', 'C++'] | 0 |
lexicographically-smallest-string-after-operations-with-constraint | Beats100%,O(n) | beats100on-by-amanbaghel-yw5n | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | AmanBaghel | NORMAL | 2024-05-09T21:09:00.691291+00:00 | 2024-05-09T21:09:00.691321+00:00 | 2 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n string getSmallestString(string s, int k) {\n ... | 0 | 0 | ['C++'] | 0 |
find-products-of-elements-of-big-array | C++ Bit count and binary search, Clean code with a lot explanitions. | c-bit-count-and-binary-search-clean-code-53jm | Intuition\n\nLet\'s think top-down and conquer each individual tasks one by one.\n\n Describe your first thoughts on how to solve this problem. \n1. The big_num | cowtony | NORMAL | 2024-05-12T00:26:31.501749+00:00 | 2024-05-12T23:52:17.618623+00:00 | 1,349 | false | # Intuition\n\nLet\'s think top-down and conquer each individual tasks one by one.\n\n<!-- Describe your first thoughts on how to solve this problem. -->\n1. The `big_nums` array is all power of 2. So we can represent it with the power only.\n ```\n [1, 2, 1, 2, 4, 1, 4, 2, 4, 1, 2, 4, 8, 1, 8, ...] (2 ^ bit)\n ... | 33 | 0 | ['Binary Search', 'Bit Manipulation', 'C++'] | 7 |
find-products-of-elements-of-big-array | [Python] Binary Search | python-binary-search-by-lee215-ez0d | Explanation\ncount(x) returns the sum of bits from 1 to x.\nmul(x) returns the pow of product of powerful arrays from 1 to x.\nquery(k) returns the pow of produ | lee215 | NORMAL | 2024-05-11T16:18:40.229069+00:00 | 2024-05-11T16:18:40.229097+00:00 | 1,218 | false | # **Explanation**\n`count(x)` returns the sum of bits from `1` to `x`.\n`mul(x)` returns the pow of product of powerful arrays from `1` to `x`.\n`query(k)` returns the pow of product of `k` first integers in `big_nums`.\n<br>\n\n# **Complexity**\nTime `O(Q * logR * logR)`\nSpace `O(Q + logR)`\n<br>\n\n\n**Python**\n```... | 12 | 2 | [] | 3 |
find-products-of-elements-of-big-array | Video Explanation (With ALL proofs) | video-explanation-with-all-proofs-by-cod-9t15 | Explanation\n\nClick here for the video\n\n# Code\n\ntypedef long long int ll;\n\nclass Solution {\n \n ll CountOf2TillX (ll x) {\n if (x <= 1) ret | codingmohan | NORMAL | 2024-05-12T17:42:41.287204+00:00 | 2024-05-12T17:42:41.287221+00:00 | 282 | false | # Explanation\n\n[Click here for the video](https://youtu.be/ku2RBhkBBIw)\n\n# Code\n```\ntypedef long long int ll;\n\nclass Solution {\n \n ll CountOf2TillX (ll x) {\n if (x <= 1) return 0;\n if (x == 2) return 1;\n if (x == 3) return 2;\n \n ll largest_i = 0;\n for (ll... | 9 | 0 | ['C++'] | 0 |
find-products-of-elements-of-big-array | Binary Search + Count contribution of each bit till given index | binary-search-count-contribution-of-each-5t33 | Intuition\nWe\'ll count frequency of each bit till index i\n\n# Approach\nmaintain two vectors vector<int> cnt1(60,0), cnt2(60, 0) where cnt1[i] = freq of ith b | artAbhi | NORMAL | 2024-05-11T16:13:17.055367+00:00 | 2024-05-11T16:25:00.057101+00:00 | 1,139 | false | # Intuition\nWe\'ll count frequency of each bit till index i\n\n# Approach\nmaintain two vectors `vector<int> cnt1(60,0), cnt2(60, 0)` where `cnt1[i] = freq of ith bit till queries[x][1] index` and `cnt2[i] = freq of ith bit till queries[x][0]-1` index\n\nThen doing `cnt1[i] - cnt2[i]` for every ith bit will tell us h... | 8 | 0 | ['Binary Search', 'Bit Manipulation', 'C++'] | 1 |
find-products-of-elements-of-big-array | Python Solution | python-solution-by-kg-profile-dwkj | \n# Code\n\nclass Solution:\n def findProductsOfElements(self, queries: List[List[int]]) -> List[int]:\n def countOnes(max_val):\n total_se | KG-Profile | NORMAL | 2024-05-11T16:15:03.943532+00:00 | 2024-05-11T16:15:03.943559+00:00 | 233 | false | \n# Code\n```\nclass Solution:\n def findProductsOfElements(self, queries: List[List[int]]) -> List[int]:\n def countOnes(max_val):\n total_set_bits = 0\n n = max_val + 1\n p = 0\n while (1 << p) <= max_val:\n total_pairs = n // (1 << (p + 1))\n ... | 6 | 0 | ['Python3'] | 1 |
find-products-of-elements-of-big-array | [Python3][Binary Search] + Bit ordering || Illustration || 800ms | python3binary-search-bit-ordering-illust-lvw2 | Intuition\n Describe your first thoughts on how to solve this problem. \nLet\'s break down the problem.\nFor each query, we have start, end, and modulus.\n- If | andrei_bis | NORMAL | 2024-05-11T21:41:12.250067+00:00 | 2024-05-11T21:41:12.250089+00:00 | 125 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nLet\'s break down the problem.\nFor each query, we have start, end, and modulus.\n- If we had a function that for a given number would give us the frequencies of the the power of 2 in the big nums array from index 0 to the queried index, ... | 4 | 0 | ['Python3'] | 3 |
find-products-of-elements-of-big-array | Python 3 || Bisearch, count 1's and accumulate 0's | python-3-bisearch-count-1s-and-accumulat-8p1r | Intuition\n Describe your first thoughts on how to solve this problem. \nFirst, bi-search the number target in the big_nums before decomposition (i.e. [1,2,3,.. | zsq007 | NORMAL | 2024-05-11T16:12:38.807902+00:00 | 2024-05-11T17:29:10.888733+00:00 | 449 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFirst, bi-search the number `target` in the `big_nums` before decomposition (i.e. `[1,2,3,...]`) such that the index `bound` falls in its decmoposition.\n\nThen, count the accumulative number of 0\'s from `1` to `target-1`, plus the resid... | 3 | 0 | ['Binary Search', 'Bit Manipulation', 'Python3'] | 0 |
find-products-of-elements-of-big-array | Java solution - 80ms | java-solution-80ms-by-darshit901-zl63 | Intuition\n Describe your first thoughts on how to solve this problem. \nFor integers in ascending order, each power of 2 is present in a pattern. Let us consid | darshit901 | NORMAL | 2024-05-11T18:29:06.831947+00:00 | 2024-05-11T18:30:26.100353+00:00 | 253 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFor integers in ascending order, each power of 2 is present in a pattern. Let us consider the numbers up to 8 for reference and list their binary representations, up to 4 digits:\n\n0 --> 0000\n1 --> 0001\n2 --> 0010\n3 --> 0011\n4 --> 01... | 2 | 0 | ['Java'] | 0 |
find-products-of-elements-of-big-array | Java Clean Solution | BiWeekly Contest | java-clean-solution-biweekly-contest-by-44zou | Code\n\n// class Solution {\n\n// private long getProduct(int[] arr) {\n// long prod = 1;\n// for (int i = 0; i < arr.length; i++) {\n// | Shree_Govind_Jee | NORMAL | 2024-05-11T16:10:45.449281+00:00 | 2024-05-11T16:10:45.449300+00:00 | 142 | false | # Code\n```\n// class Solution {\n\n// private long getProduct(int[] arr) {\n// long prod = 1;\n// for (int i = 0; i < arr.length; i++) {\n// prod *= arr[i];\n// }\n// return prod;\n// }\n\n// public int[] findProductsOfElements(long[][] queries) {\n// int... | 2 | 2 | ['Array', 'Bit Manipulation', 'Bitmask', 'Java'] | 1 |
find-products-of-elements-of-big-array | 💥💥 Beats 100% on runtime and memory [EXPLAINED] | beats-100-on-runtime-and-memory-explaine-kaha | IntuitionWe have to count the number of set bits (1s) in a number efficiently. A direct approach would be too slow, so I used dynamic programming (via memoizati | r9n | NORMAL | 2025-01-30T16:18:52.896981+00:00 | 2025-01-30T16:18:52.896981+00:00 | 4 | false | # Intuition
We have to count the number of set bits (1s) in a number efficiently. A direct approach would be too slow, so I used dynamic programming (via memoization) to store and reuse results for previously calculated numbers. This way, I didn’t have to recompute the same values multiple times, which greatly improves... | 1 | 0 | ['Array', 'Math', 'Binary Search', 'Dynamic Programming', 'Bit Manipulation', 'Simulation', 'Binary Tree', 'Bitmask', 'Kotlin'] | 0 |
find-products-of-elements-of-big-array | most overcomplicated python solution??? | most-overcomplicated-python-solution-by-cbx5i | Approach\nCounted the total number of set bits within a range of numbers [1, n] to find the index of a certain number in the large array. Used binary search to | bool3 | NORMAL | 2024-05-12T17:47:51.767460+00:00 | 2024-05-12T17:47:51.767496+00:00 | 52 | false | # Approach\nCounted the total number of set bits within a range of numbers [1, n] to find the index of a certain number in the large array. Used binary search to get from an index to a number. Counted the frequency of certain bits within a range and multiplied each bit\'s frequency into a cumulative variable by using b... | 1 | 0 | ['Python3'] | 0 |
find-products-of-elements-of-big-array | Easy to understand || Beats 100% || Bit Manipulation + Binary Search || C++ | easy-to-understand-beats-100-bit-manipul-8g5j | Complexity\n- Time complexity:O(q.log^2n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(logn)\n Add your space complexity here, e.g. O(n) | dubeyad2003 | NORMAL | 2024-05-11T19:29:22.216030+00:00 | 2024-05-12T04:52:19.834799+00:00 | 118 | false | # Complexity\n- Time complexity:$$O(q.log^2n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(logn)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n using ll = long long;\n // binary exponentiation for computing the power of t... | 1 | 2 | ['C++'] | 0 |
find-products-of-elements-of-big-array | Complicated recurrence, faster than 100% | complicated-recurrence-faster-than-100-b-b6hq | Intuition\n Describe your first thoughts on how to solve this problem. \nThe answer is a power of 2 modulo the given mod. It suffices to keep track of the power | mbeceanu | NORMAL | 2024-05-11T18:22:46.560458+00:00 | 2024-05-16T03:09:43.609749+00:00 | 113 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe answer is a power of 2 modulo the given mod. It suffices to keep track of the power of 2 and further it suffices to compute the total power of 2 from the start of the array up to each given index, then subtract the lower bound from th... | 1 | 1 | ['Python3'] | 0 |
find-products-of-elements-of-big-array | Dynamic Programming and Binary Search for Powerful Array Queries | dynamic-programming-and-binary-search-fo-e8v4 | Intuition\nThe problem requires finding products of elements within a certain range modulo a given number. To efficiently solve this problem, we can use dynamic | pavan_riser | NORMAL | 2024-05-11T16:40:35.634112+00:00 | 2024-05-11T16:40:35.634131+00:00 | 348 | false | # Intuition\n**The problem requires finding products of elements within a certain range modulo a given number. To efficiently solve this problem, we can use dynamic programming to calculate the number of bits required to represent a number, perform binary search to find the maximum number within a given range, and calc... | 1 | 0 | ['Binary Search', 'Dynamic Programming', 'C++'] | 0 |
find-products-of-elements-of-big-array | 🔥🔥 Beats 100.00% || 3772ms || Hard 🔥🔥 | beats-10000-3772ms-hard-by-umair__saad-ch56 | \n\n# Code\nPython []\ndef getcount(n, k):\n n += 1\n res = (n >> (k + 1)) << k\n if (n >> k) & 1:\n res += n & ((1 << k) - 1)\n return res\n | Umair__Saad | NORMAL | 2024-05-11T16:05:19.644646+00:00 | 2024-05-11T16:05:19.644664+00:00 | 210 | false | \n\n# Code\n```Python []\ndef getcount(n, k):\n n += 1\n res = (n >> (k + 1)) << k\n if (n >> k) & 1:\n res += n & ((1 << k) - 1)\n return res\n\ndef gettotal(n):\n res = 0\n for b in range(60):\n res += getcount(n, b)\n return res\n\nclass Solution:\n def findProductsOfElements(se... | 1 | 2 | ['Python3'] | 0 |
find-products-of-elements-of-big-array | Count bits in range using BS | count-bits-in-range-using-bs-by-theabbie-bc3n | \ndef getcount(n, k):\n n += 1\n res = (n >> (k + 1)) << k\n if (n >> k) & 1:\n res += n & ((1 << k) - 1)\n return res\n\ndef gettotal(n):\n | theabbie | NORMAL | 2024-05-11T16:01:02.534971+00:00 | 2024-05-11T16:01:02.535014+00:00 | 203 | false | ```\ndef getcount(n, k):\n n += 1\n res = (n >> (k + 1)) << k\n if (n >> k) & 1:\n res += n & ((1 << k) - 1)\n return res\n\ndef gettotal(n):\n res = 0\n for b in range(60):\n res += getcount(n, b)\n return res\n\nclass Solution:\n def findProductsOfElements(self, queries: List[Lis... | 1 | 1 | ['Python'] | 0 |
find-products-of-elements-of-big-array | Modular Code | Observations | Visualisation | modular-code-observations-visualisation-sl0zh | Here's how i visualised the solution :Calculation of no. of setbits at a position i for numbers from 0 to x
consider (0 based), cycle starts at 0
f(i,x) = 2^i * | lokeshwar777 | NORMAL | 2025-02-07T07:08:58.686403+00:00 | 2025-02-07T07:20:33.995811+00:00 | 9 | false | Here's how i visualised the solution :

### Calculation of no. of setbits at a position i for numbers from 0 to x
- consider (0 based), cycle starts at 0
- `f(i,x) = 2^i * (x+1)/(2^(i+1)) + max(0,(x+1)%(... | 0 | 0 | ['Binary Search', 'Bit Manipulation', 'Counting', 'Prefix Sum', 'Python3'] | 0 |
find-products-of-elements-of-big-array | Explained bit manipulation, clean code | explained-bit-manipulation-clean-code-by-ct93 | Approach
For each query [L, R, MOD], we:
Calculate counts of powers of 2 up to L and R+1
Use difference array technique to get counts in range [L, R]
Compute | ivangnilomedov | NORMAL | 2025-01-05T14:30:37.863562+00:00 | 2025-01-05T14:30:37.863562+00:00 | 9 | false | # Approach
1. For each query [L, R, MOD], we:
- Calculate counts of powers of 2 up to L and R+1
- Use difference array technique to get counts in range [L, R]
- Compute product using modular exponentiation
2. The core bit manipulation magic happens in `calculate_pow2_counts_till_value`:
- Visualize numbers... | 0 | 0 | ['C++'] | 0 |
find-products-of-elements-of-big-array | using binary search | using-binary-search-by-prazz_18-pb3e | null | prazz_18 | NORMAL | 2024-12-10T11:26:40.567256+00:00 | 2024-12-10T11:26:40.567256+00:00 | 6 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | 0 | ['C++'] | 0 |
find-products-of-elements-of-big-array | Multiple Ques in a single ques. || Binomial Modularity || Binary search || O(logn) || Math | multiple-ques-in-a-single-ques-binomial-9ea8h | \n# Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \nO(logn)\n- Space complexity:\n Add your space complexity here, e.g. O(n) \nO(n)\ | Priyanshu_pandey15 | NORMAL | 2024-08-29T19:13:34.358446+00:00 | 2024-08-29T19:15:36.685855+00:00 | 9 | false | \n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(logn)$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n# Code\n```java []\nclass Solution {\n \n public int[] findProductsOfElements(long[][] queries) {\n int n = queries.... | 0 | 0 | ['Array', 'Math', 'Binary Search', 'Bit Manipulation', 'Java'] | 0 |
find-products-of-elements-of-big-array | 520 ms | 520-ms-by-0x81-xva5 | ruby\ndef pref t\n rc = 0\n x = (0..[t, 45 * 10 ** 12].min).bsearch do | x |\n c = 0\n d = 1\n y = d << 1\n while d <= x\n | 0x81 | NORMAL | 2024-08-04T11:03:21.013655+00:00 | 2024-08-04T11:18:51.421043+00:00 | 3 | false | ```ruby\ndef pref t\n rc = 0\n x = (0..[t, 45 * 10 ** 12].min).bsearch do | x |\n c = 0\n d = 1\n y = d << 1\n while d <= x\n a, b = x .divmod y\n c += a * d + (b - d.pred).clamp(0, d)\n d <<= 1\n y <<= 1\n end\n c >= t && !!(rc... | 0 | 0 | ['Ruby'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.