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-palindrome
Lexicographically Smallest Palindrome Solution in C++
lexicographically-smallest-palindrome-so-27li
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
The_Kunal_Singh
NORMAL
2023-05-26T04:08:09.611109+00:00
2023-05-26T04:08:09.611135+00:00
63
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)$$ -->\nO(n)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$...
2
0
['C++']
0
lexicographically-smallest-palindrome
Easy Solution in Java | 8 ms - 100% beats | Fully Explained
easy-solution-in-java-8-ms-100-beats-ful-xgrl
\n\n# Approach\n\nTo solve the problem, we follow these steps:\n\n1. Convert the input string s into a character array arr for easy manipulation.\n2. Determine
akobirswe
NORMAL
2023-05-23T16:02:42.630730+00:00
2023-07-03T20:32:26.659192+00:00
164
false
\n\n# Approach\n\nTo solve the problem, we follow these steps:\n\n1. Convert the input string `s` into a character array `arr` for easy manipulation.\n2. Determine the length of the array and store it in the variable `n`.\n3. Iterate over the array from the beginning (`i = 0`) to the middle (`i < n / 2`).\n4. Check if ...
2
0
['Array', 'Two Pointers', 'String', 'Java']
0
lexicographically-smallest-palindrome
[JavaScript] 2697. Lexicographically Smallest Palindrome
javascript-2697-lexicographically-smalle-feb1
---\n\nWeekly Contest 346 solutions:\n- Q1 - https://leetcode.com/problems/minimum-string-length-after-removing-substrings/solutions/3547566/javascript-2696-min
pgmreddy
NORMAL
2023-05-21T06:43:02.488269+00:00
2023-05-21T06:47:26.528402+00:00
675
false
---\n\nWeekly Contest 346 solutions:\n- Q1 - https://leetcode.com/problems/minimum-string-length-after-removing-substrings/solutions/3547566/javascript-2696-minimum-string-length-after-removing-substrings/\n- Q2 - https://leetcode.com/problems/lexicographically-smallest-palindrome/solutions/3547563/javascript-2697-lexi...
2
0
['JavaScript']
0
lexicographically-smallest-palindrome
Easily understandable C++ solution
easily-understandable-c-solution-by-heal-x56p
Intuition\nJust try to make the (i)th and (l-1-i)th characters same with the given condition (The lower value charater shoulb be taken) #where l is the length o
Healthy_UG_007
NORMAL
2023-05-21T05:58:34.036638+00:00
2023-05-21T05:58:34.036663+00:00
73
false
# Intuition\nJust try to make the (i)th and (l-1-i)th characters same with the given condition (The lower value charater shoulb be taken) #where l is the length of th string\n\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nUse a for loop and iterate upto the middle and try to make t...
2
0
['String', 'C++']
0
lexicographically-smallest-palindrome
| | ✅ Very Simple C++ Solution with 100% Time and Space Complexity ✅ | |
very-simple-c-solution-with-100-time-and-bmb4
Intuition\nPlease UPVOTE if you LIKE the Solution and COMMENT your own Code and thoughts.\n\n# Approach\nThese Type of Questions are Solved using Two pointers,\
Satyam_Singh_Nijwala
NORMAL
2023-05-21T05:04:04.605848+00:00
2023-05-21T05:04:04.605887+00:00
218
false
# Intuition\nPlease UPVOTE if you LIKE the Solution and COMMENT your own Code and thoughts.\n\n# Approach\nThese Type of Questions are Solved using Two pointers,\nOne from Starting index i=0 and other from end r=size of string -1.\n\n# Complexity\n- Time complexity:\n100%\n\n- Space complexity:\n100%\n\n# Code\n```\ncl...
2
0
['C++']
0
lexicographically-smallest-palindrome
Easiest 2 Pointers Approach | Short code explained
easiest-2-pointers-approach-short-code-e-i3wj
Intuition\nWe need to make the string palindrome. Thus we need to compare first and last indices.\n\n# Approach\n- (step 1) Keep one index at beginning of strin
Jeetaksh
NORMAL
2023-05-21T04:40:26.862455+00:00
2023-05-21T04:40:26.862489+00:00
122
false
# Intuition\nWe need to make the string palindrome. Thus we need to compare first and last indices.\n\n# Approach\n- **(step 1)** Keep one index at beginning of string and other at the end.\n- **(case 1)** Update the first index to the character at last index if last index character is alphabetically smaller.\n- **(cas...
2
0
['C++']
0
lexicographically-smallest-palindrome
Simplest of all solution | Super easy to understand
simplest-of-all-solution-super-easy-to-u-5vw8
Just compare front and back letters.\n- If they are not equal then replace the larger letter with the smaller one.\n\n# Code\n\nclass Solution:\n def makeSma
younus-Sid
NORMAL
2023-05-21T04:27:30.747284+00:00
2023-05-21T04:27:30.747320+00:00
659
false
- Just compare front and back letters.\n- If they are not equal then replace the larger letter with the smaller one.\n\n# Code\n```\nclass Solution:\n def makeSmallestPalindrome(self, s: str) -> str:\n for i in range(int(len(s)/2)):\n if s[i] != s[len(s)-i-1]:\n if s[i] < s[len(s)-i-...
2
0
['Python3']
0
lexicographically-smallest-palindrome
C++ || Easiest 4 lines of code
c-easiest-4-lines-of-code-by-mrigank_200-tjom
Here is my c++ code for this problem.\n\n# Complexity\n- Time complexity:O(n/2)\n\n- Space complexity:O(1)\n\n# Code\n\nclass Solution {\npublic:\n string ma
mrigank_2003
NORMAL
2023-05-21T04:25:23.190296+00:00
2023-05-21T04:25:23.190336+00:00
540
false
Here is my c++ code for this problem.\n\n# Complexity\n- Time complexity:$$O(n/2)$$\n\n- Space complexity:$$O(1)$$\n\n# Code\n```\nclass Solution {\npublic:\n string makeSmallestPalindrome(string s) {\n for(int i=0; i<s.size()/2; i++){\n if(s[i]!=s[s.size()-1-i]){\n (s[i]<s[s.size()-...
2
0
['String', 'C++']
1
lexicographically-smallest-palindrome
EASIEST JAVA SOLUTION EVER
easiest-java-solution-ever-by-nikhil_rat-s9kv
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
nikhil_rathi93
NORMAL
2023-05-21T04:15:31.398198+00:00
2023-05-21T04:18:37.737871+00:00
553
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)$$ --...
2
0
['C++', 'Java']
0
lexicographically-smallest-palindrome
JAVA Easy SOlution || 100 Faster
java-easy-solution-100-faster-by-mayur01-v5k7
\n- Time complexity: O(n)\n\n- Space complexity: O(n)\n\n\nclass Solution {\n public String makeSmallestPalindrome(String s) {\n \n char []ch=s.toC
mayur0106
NORMAL
2023-05-21T04:06:34.981335+00:00
2023-05-21T04:06:34.981366+00:00
280
false
\n- Time complexity: O(n)\n\n- Space complexity: O(n)\n\n```\nclass Solution {\n public String makeSmallestPalindrome(String s) {\n \n char []ch=s.toCharArray();\n \n int i=0;\n int j=s.length()-1;\n while(i<=j)\n {\n if(ch[i]<ch[j])ch[j]=ch[i];\n els...
2
0
['Java']
0
lexicographically-smallest-palindrome
EASY SOLUTION USING LOOPS || BRUTE FORCE BEATING 100% || C++ & JAVA SOLUTION
easy-solution-using-loops-brute-force-be-mk6z
IntuitionTo convert the given string into a palindrome with the minimum number of operations, we need to ensure that the string reads the same forward and backw
arshi_bansal
NORMAL
2025-03-15T10:11:40.223170+00:00
2025-03-15T10:11:40.223170+00:00
93
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> To convert the given string into a palindrome with the minimum number of operations, we need to ensure that the string reads the same forward and backward. For each character s[i] in the first half, it should match its corresponding charact...
1
0
['Two Pointers', 'String', 'Greedy', 'C++', 'Java']
0
lexicographically-smallest-palindrome
☑️ Golang solution
golang-solution-by-codemonkey80s-jl5v
Code
CodeMonkey80s
NORMAL
2025-01-28T00:25:41.604377+00:00
2025-01-28T00:25:41.604377+00:00
34
false
# Code ```golang [] func makeSmallestPalindrome(s string) string { output := []byte(s) for i, j := 0, len(s)-1; i <= j; i, j = i+1, j-1 { if s[i] == s[j] { continue } output[i] = min(s[i], s[j]) output[j] = output[i] } return string(output) } ```
1
0
['Go']
0
lexicographically-smallest-palindrome
Легчайшая
legchaishaia-by-danisdeveloper-zpte
Code
DanisDeveloper
NORMAL
2025-01-03T11:18:39.656020+00:00
2025-01-03T11:18:39.656020+00:00
45
false
# Code ```cpp [] class Solution { public: string makeSmallestPalindrome(string s) { int n = s.length(); for(int i=0;i<n/2;++i){ char* left = &s[i]; char* right = &s[n - i - 1]; char diff = *right - *left; if(diff == 0) continue; if(diff > 0...
1
0
['C++']
0
lexicographically-smallest-palindrome
Two pointers, in place.
two-pointers-in-place-by-michelusa-w6un
As we are ask for a palindrome, it is intuitive to track from both: start of string and end of string Because we are asked for minimum, apply minimum character
michelusa
NORMAL
2024-12-29T23:56:14.704999+00:00
2024-12-29T23:56:14.704999+00:00
105
false
As we are ask for a palindrome, it is intuitive to track from both: * start of string * and end of string Because we are asked for minimum, apply minimum character if the two compared elements are different. O(N) # Code ```cpp [] class Solution { public: string makeSmallestPalindrome(string s) { for (siz...
1
0
['Two Pointers', 'C++']
0
lexicographically-smallest-palindrome
Python Simple Code
python-simple-code-by-nagaraj08-4fxu
\n# Code\n\nclass Solution(object):\n def makeSmallestPalindrome(self, s):\n """\n :type s: str\n :rtype: str\n """\n i =
NAGARAJ08
NORMAL
2024-08-11T07:25:43.264159+00:00
2024-08-11T07:25:43.264188+00:00
263
false
\n# Code\n```\nclass Solution(object):\n def makeSmallestPalindrome(self, s):\n """\n :type s: str\n :rtype: str\n """\n i = 0\n j = len(s)-1\n\n s = list(s)\n while i <j:\n\n if s[i]!=s[j]:\n if s[i]<s[j]:\n s[j] = ...
1
0
['Python']
0
lexicographically-smallest-palindrome
Java | JavaScript | TypeScript | C++ | C# | Kotlin | Go Solution.
java-javascript-typescript-c-c-kotlin-go-o1va
Java []\npublic class Solution {\n\n public String makeSmallestPalindrome(String s) {\n char[] lexicographicallySmallestPalindrome = s.toCharArray();\
LachezarTsK
NORMAL
2024-07-15T16:32:12.168156+00:00
2024-07-15T16:37:25.007147+00:00
63
false
```Java []\npublic class Solution {\n\n public String makeSmallestPalindrome(String s) {\n char[] lexicographicallySmallestPalindrome = s.toCharArray();\n int left = 0;\n int right = lexicographicallySmallestPalindrome.length - 1;\n\n while (left < right) {\n if (lexicographica...
1
0
['C++', 'Java', 'Go', 'TypeScript', 'Kotlin', 'JavaScript', 'C#']
0
lexicographically-smallest-palindrome
✅ Easy C++ Solution
easy-c-solution-by-moheat-8gzk
Code\n\nclass Solution {\npublic:\n string makeSmallestPalindrome(string s) {\n int n = s.size();\n int left = 0;\n int right = n-1;\n
moheat
NORMAL
2024-07-04T07:29:23.925560+00:00
2024-07-04T07:29:23.925595+00:00
225
false
# Code\n```\nclass Solution {\npublic:\n string makeSmallestPalindrome(string s) {\n int n = s.size();\n int left = 0;\n int right = n-1;\n while(left < right)\n {\n if(s[left] != s[right])\n {\n char most = (s[left] < s[right]) ? s[left] : s[ri...
1
0
['C++']
0
lexicographically-smallest-palindrome
[Python] O(N) using two pointers
python-on-using-two-pointers-by-pbelskiy-r01l
\nclass Solution:\n def makeSmallestPalindrome(self, s: str) -> str:\n a = list(s)\n\n left, right = 0, len(a) - 1\n\n while left < righ
pbelskiy
NORMAL
2024-06-10T14:46:51.071769+00:00
2024-06-10T14:46:51.071807+00:00
40
false
```\nclass Solution:\n def makeSmallestPalindrome(self, s: str) -> str:\n a = list(s)\n\n left, right = 0, len(a) - 1\n\n while left < right:\n a[left] = a[right] = min(a[left], a[right])\n left += 1\n right -= 1\n \n return \'\'.join(a)\n```
1
0
['Two Pointers', 'Python']
0
lexicographically-smallest-palindrome
[Java] Easy 100% solution
java-easy-100-solution-by-ytchouar-zc45
java\nclass Solution {\n public String makeSmallestPalindrome(final String s) {\n final char str[] = s.toCharArray();\n int i = 0, j = s.length
YTchouar
NORMAL
2024-05-07T02:27:30.175283+00:00
2024-05-07T02:27:30.175310+00:00
228
false
```java\nclass Solution {\n public String makeSmallestPalindrome(final String s) {\n final char str[] = s.toCharArray();\n int i = 0, j = s.length() - 1;\n\n while(i < j) {\n str[i] = (char) Math.min(str[i], str[j]);\n str[j--] = str[i++];\n }\n\n return new S...
1
0
['Java']
0
lexicographically-smallest-palindrome
Python solution, fast and intuitive
python-solution-fast-and-intuitive-by-se-kvm9
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
Semako123
NORMAL
2024-03-26T19:00:00.441896+00:00
2024-03-26T19:00:00.441921+00:00
120
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-palindrome
Simple java code 5 ms beats 100 %
simple-java-code-5-ms-beats-100-by-arobh-obaf
\n# Complexity\n- \n\n# Code\n\nclass Solution {\n public String makeSmallestPalindrome(String s) {\n int l = 0;\n int r = s.length() - 1;\n
Arobh
NORMAL
2024-01-31T15:09:38.763123+00:00
2024-01-31T15:09:38.763153+00:00
8
false
\n# Complexity\n- \n![image.png](https://assets.leetcode.com/users/images/72380c05-0fea-4248-8e3a-84ce7ef3b1b3_1706713762.7482114.png)\n# Code\n```\nclass Solution {\n public String makeSmallestPalindrome(String s) {\n int l = 0;\n int r = s.length() - 1;\n char[] arr = s.toCharArray();\n ...
1
0
['Two Pointers', 'String', 'Java']
0
lexicographically-smallest-palindrome
java beats 100%
java-beats-100-by-susahin80-kw97
Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n\nclass Solution {\n public String makeSmallestPalindrome(String s) {\n c
susahin80
NORMAL
2023-11-19T13:24:18.031494+00:00
2023-11-19T13:24:18.031518+00:00
56
false
# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution {\n public String makeSmallestPalindrome(String s) {\n char[] chars = s.toCharArray();\n int l = 0;\n int r = chars.length - 1;\n\n while (l < r) {\n int min = Math.min(chars[l], ...
1
0
['Java']
0
lexicographically-smallest-palindrome
Super easy solution in JS. WOW.
super-easy-solution-in-js-wow-by-azamata-v05d
\n# Code\n\n/**\n * @param {string} s\n * @return {string}\n */\nvar makeSmallestPalindrome = function(s) {\n let str = s.split(\'\')\n for(let i = s.leng
AzamatAbduvohidov
NORMAL
2023-08-12T05:15:02.754661+00:00
2023-08-12T05:15:02.754682+00:00
451
false
\n# Code\n```\n/**\n * @param {string} s\n * @return {string}\n */\nvar makeSmallestPalindrome = function(s) {\n let str = s.split(\'\')\n for(let i = s.length - 1, j = 0; i >= Math.ceil(s.length / 2); i--, j++) {\n if(str[i] < str[j]) {\n str[j] = str[i]\n } else {\n str[i] = ...
1
0
['JavaScript']
0
lexicographically-smallest-palindrome
C# easy
c-easy-by-ghmarek-qiug
Code\n\npublic class Solution {\n public string MakeSmallestPalindrome(string s) {\n \n char[] sArr = s.ToArray();\n\n for (int i = 0, j
GHMarek
NORMAL
2023-06-27T15:01:03.500676+00:00
2023-06-27T15:01:03.500706+00:00
90
false
# Code\n```\npublic class Solution {\n public string MakeSmallestPalindrome(string s) {\n \n char[] sArr = s.ToArray();\n\n for (int i = 0, j = s.Length - 1; j >= s.Length / 2; j--, i++)\n {\n if (s[i] != s[j])\n {\n if (s[i] < s[j])\n {...
1
0
['C#']
0
lexicographically-smallest-palindrome
CPP || Easy Solution || 27 ms || 97%beats|| O(1) space || O(N) time
cpp-easy-solution-27-ms-97beats-o1-space-44ri
Intuition\n Describe your first thoughts on how to solve this problem. \nThe intuition is simple we have to make the string palindrome which is our first priori
aks1719
NORMAL
2023-05-30T17:03:35.279753+00:00
2023-05-30T17:04:08.777233+00:00
7
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition is simple we have to make the string palindrome which is our first priority so simply i can check that it is palindrom or not and second task is that it should be Lexicographically Smallest Palindrome so when the string pali...
1
0
['String', 'C++']
0
lexicographically-smallest-palindrome
JAVA | One pass
java-one-pass-by-sourin_bruh-63e2
Solution:\n\nclass Solution {\n public String makeSmallestPalindrome(String s) {\n int n = s.length();\n StringBuilder sb = new StringBuilder()
sourin_bruh
NORMAL
2023-05-23T17:32:25.872792+00:00
2023-05-23T17:32:25.872832+00:00
22
false
# Solution:\n```\nclass Solution {\n public String makeSmallestPalindrome(String s) {\n int n = s.length();\n StringBuilder sb = new StringBuilder();\n for (int i = 0; i < n; i++) {\n sb.append((char) Math.min(s.charAt(i), s.charAt(n - i - 1)));\n }\n return sb.toString(...
1
0
['String', 'Java']
0
lexicographically-smallest-palindrome
python3; 214 ms; 16.5 MB
python3-214-ms-165-mb-by-nurmukhamed1-i7zh
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
Nurmukhamed1
NORMAL
2023-05-23T13:58:04.891049+00:00
2023-05-23T13:58:04.891097+00:00
858
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: 214 ms\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: 16.5 MB\n<!-- Add your space complexity here, e...
1
0
['Python3']
1
lexicographically-smallest-palindrome
Replace with Minimum
replace-with-minimum-by-_kitish-n30f
Code\n\nclass Solution {\npublic:\n string makeSmallestPalindrome(string s) {\n int n = size(s);\n for(int i=0; i<=n/2; ++i){\n if(s
_kitish
NORMAL
2023-05-21T19:58:03.065051+00:00
2023-05-21T19:58:03.065082+00:00
28
false
# Code\n```\nclass Solution {\npublic:\n string makeSmallestPalindrome(string s) {\n int n = size(s);\n for(int i=0; i<=n/2; ++i){\n if(s[i] != s[n-i-1]){\n char e = min(s[i],s[n-i-1]);\n s[i] = e;\n s[n-i-1] = e;\n }\n }\n ...
1
0
['C++']
0
lexicographically-smallest-palindrome
Two Pointer || Very easy to understand || Java
two-pointer-very-easy-to-understand-java-gvwl
\n# Approach\n Describe your approach to solving the problem. \n- Take two pointers, one at the 0th index and one at last index.\n- Check if the characters at b
sahilgupta8470
NORMAL
2023-05-21T10:45:40.904320+00:00
2023-05-21T10:45:40.904358+00:00
27
false
\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- Take two pointers, one at the 0th index and one at last index.\n- Check if the characters at both pointers are same or not.\n- If not same, then check which character is lexicographically smaller.\n- Change the bigger character to smaller characte...
1
0
['Two Pointers', 'String', 'Java']
0
lexicographically-smallest-palindrome
C++ || EASY || SIMPLE
c-easy-simple-by-arya_ratan-1tfp
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
arya_ratan
NORMAL
2023-05-21T09:36:39.540465+00:00
2023-05-21T09:36:39.540569+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
['C++']
0
lexicographically-smallest-palindrome
Simple Easy Javascript Solution 100% beats 51.7 MB Memory
simple-easy-javascript-solution-100-beat-qz00
Code\n\n/**\n * @param {string} s\n * @return {string}\n */\nvar makeSmallestPalindrome = function(s) {\nlet newString = ""\nfor(let i=0 ; i< s.length ; i ++){\
dnt1997
NORMAL
2023-05-21T09:10:08.286742+00:00
2023-05-21T09:10:08.286784+00:00
154
false
# Code\n```\n/**\n * @param {string} s\n * @return {string}\n */\nvar makeSmallestPalindrome = function(s) {\nlet newString = ""\nfor(let i=0 ; i< s.length ; i ++){\n let firstWord = s.charAt(i);\n let lastWord = s.charAt(s.length -i - 1);\n if(firstWord!==lastWord){\n if(firstWord.charCodeAt(0)>lastWor...
1
0
['JavaScript']
0
lexicographically-smallest-palindrome
Clean PY
clean-py-by-bariscan97-btvj
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
Bariscan97
NORMAL
2023-05-21T06:52:14.822036+00:00
2023-05-21T06:52:14.822076+00:00
559
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
1
['Array', 'String', 'String Matching', 'Python', 'Python3']
1
lexicographically-smallest-palindrome
c++ O(n) solution Two Pointers
c-on-solution-two-pointers-by-augus7-42o4
\n Describe your first thoughts on how to solve this problem. \n\n# Approach: Two Pointers\n Describe your approach to solving the problem. \n\n# Complexity\n-
Augus7
NORMAL
2023-05-21T05:25:35.524682+00:00
2023-05-21T05:25:35.524721+00:00
192
false
\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach: Two Pointers\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 ...
1
0
['Two Pointers', 'String', 'C++']
1
lexicographically-smallest-palindrome
easy and simple solution
easy-and-simple-solution-by-rahul_pinto-v0zm
\n# Complexity\n- Time complexity:$O(n/2)$\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)
rahul_pinto
NORMAL
2023-05-21T05:23:58.680280+00:00
2023-05-21T05:23:58.680332+00:00
9
false
\n# Complexity\n- Time complexity:$O(n/2)$\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 makeSmallestPalindrome(string s) \n {\n int first=0;\n int last=s....
1
0
['C++']
0
lexicographically-smallest-palindrome
Simple Solution || Easy To Understand
simple-solution-easy-to-understand-by-dc-8iez
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
Dcoder_53
NORMAL
2023-05-21T04:30:53.975457+00:00
2023-05-25T07:07:36.858883+00:00
84
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<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n ...
1
0
['C++']
1
lexicographically-smallest-palindrome
Simple Two Pointer Solution | Java
simple-two-pointer-solution-java-by-raja-gvyl
Approach: Take two pointers one at 0 index other at last-1 at each iteration replace the large character with smaller one in stringbuilder return the string at
Rajat069
NORMAL
2023-05-21T04:24:59.268776+00:00
2023-05-21T04:24:59.268803+00:00
115
false
**Approach:** Take two pointers one at 0 index other at last-1 at each iteration replace the large character with smaller one in stringbuilder return the string at last.\n```\nclass Solution {\n public String makeSmallestPalindrome(String s) {\n StringBuilder sb = new StringBuilder(s);\n int f=0,l=s.le...
1
0
['Java']
0
lexicographically-smallest-palindrome
Beats 100% Solutions
beats-100-solutions-by-deleted_user-vn95
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
deleted_user
NORMAL
2023-05-21T04:23:11.268618+00:00
2023-05-21T04:23:11.268661+00:00
171
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```\n/**\n * @param {string} s\n * @return {string}\n */\nvar makeSmallestPalindrome =...
1
0
['JavaScript']
1
lexicographically-smallest-palindrome
Lexicographically Smallest Palindrome || C++
lexicographically-smallest-palindrome-c-2feat
\n# Code\n\nclass Solution {\npublic:\n string makeSmallestPalindrome(string s) {\n int i=0;\n int j=s.size()-1;\n \n while(i<j){\n
krish_kakadiya
NORMAL
2023-05-21T04:18:20.769805+00:00
2023-05-21T04:18:20.769847+00:00
367
false
\n# Code\n```\nclass Solution {\npublic:\n string makeSmallestPalindrome(string s) {\n int i=0;\n int j=s.size()-1;\n \n while(i<j){\n if(s[i]!=s[j]){\n if(int(s[i])>int(s[j])) s[i]=s[j];\n else s[j]=s[i];\n }\n i++;\n ...
1
0
['C++']
0
lexicographically-smallest-palindrome
Simple C++ Solution
simple-c-solution-by-roytanmay-5fia
Intuition\n Describe your first thoughts on how to solve this problem. \nTake the smallest from s[i] and s[n-i-1] for every index (0 <= i < n/2)\n\n# Complexit
roytanmay
NORMAL
2023-05-21T04:13:16.982851+00:00
2023-05-21T04:13:16.982887+00:00
11
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTake the smallest from s[i] and s[n-i-1] for every index (0 <= i < n/2)\n\n# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n\n# Code\n```\nclass Solution {\npublic:\n string makeSmall...
1
0
['C++']
0
lexicographically-smallest-palindrome
very simple and easy to understand solution
very-simple-and-easy-to-understand-solut-1z2q
\n\n# Code\n\nclass Solution:\n def makeSmallestPalindrome(self, s: str) -> str:\n def helper(s) :\n if len(s) <2 :\n return
Vivek_Raj_
NORMAL
2023-05-21T04:09:49.544557+00:00
2023-05-21T04:09:49.544589+00:00
358
false
\n\n# Code\n```\nclass Solution:\n def makeSmallestPalindrome(self, s: str) -> str:\n def helper(s) :\n if len(s) <2 :\n return s\n \n \n if ord(s[0]) <= ord(s[-1]) :\n return s[0] + helper(s[1:len(s)-1]) +s[0]\n else :\n ...
1
1
['Python3']
1
lexicographically-smallest-palindrome
Check if you need to change character, if yes, change to smaller
check-if-you-need-to-change-character-if-1mkb
Intuition\nCheck for every position until the half of the string, check if elements are the same:\n - if yes, nothing to be done\n - if no, modify one of them b
salvadordali
NORMAL
2023-05-21T04:04:33.281796+00:00
2023-05-21T04:24:38.147928+00:00
801
false
# Intuition\nCheck for every position until the half of the string, check if elements are the same:\n - if yes, nothing to be done\n - if no, modify one of them by changing it to a smaller character\n\n\n\n# Complexity\n- Time complexity: $O(n)$\n- Space complexity: $O(n)$\n\n# Code\n\n```Rust []\nimpl Solution {\n pu...
1
0
['Python3', 'Rust']
0
lexicographically-smallest-palindrome
Two pointer Approach only EASY TO UNDERSTAND
two-pointer-approach-only-easy-to-unders-oj0t
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
ajayadhikari
NORMAL
2023-05-21T04:03:17.383166+00:00
2023-05-21T04:03:17.383225+00:00
20
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
1
['Python', 'C++', 'Java', 'Python3', 'MS SQL Server']
0
lexicographically-smallest-palindrome
Very simple and Easy Solution⚡🔥🔥
very-simple-and-easy-solution-by-yashpad-gjaj
\n# Code\n\nclass Solution {\npublic:\n string makeSmallestPalindrome(string s) {\n int i=0;\n int j=s.size()-1;\n \n \n s
yashpadiyar4
NORMAL
2023-05-21T04:02:46.446588+00:00
2023-05-21T04:02:46.446623+00:00
149
false
\n# Code\n```\nclass Solution {\npublic:\n string makeSmallestPalindrome(string s) {\n int i=0;\n int j=s.size()-1;\n \n \n string ans;\n while(i<j){\n if(s[i]!=s[j]){\n ans+=min(s[i],s[j]);\n }\n else{\n ans+=s[...
1
0
['C++']
1
lexicographically-smallest-palindrome
Java || O(n)
java-on-by-nishant7372-4wkj
java []\nclass Solution {\n public String makeSmallestPalindrome(String s) {\n int i=0;\n int j=s.length()-1;\n char[] arr = s.toCharArr
nishant7372
NORMAL
2023-05-21T04:02:41.640210+00:00
2023-05-21T04:02:41.640247+00:00
721
false
``` java []\nclass Solution {\n public String makeSmallestPalindrome(String s) {\n int i=0;\n int j=s.length()-1;\n char[] arr = s.toCharArray();\n while(i<=j){\n if(arr[i]!=arr[j]){\n arr[i] = arr[j] = (char) Math.min(arr[i],arr[j]);\n }\n ...
1
0
['Java']
0
lexicographically-smallest-palindrome
Java
java-by-neel_diyora-qgl8
Code\n\nclass Solution {\n public String makeSmallestPalindrome(String s) {\n char[] ch = s.toCharArray();\n int start = 0;\n int end =
anjan_diyora
NORMAL
2023-05-21T04:02:33.206016+00:00
2023-05-21T04:02:33.206057+00:00
249
false
# Code\n```\nclass Solution {\n public String makeSmallestPalindrome(String s) {\n char[] ch = s.toCharArray();\n int start = 0;\n int end = s.length() - 1;\n \n while(start <= end) {\n if(ch[start] != ch[end]) {\n if(ch[end] > ch[start]) {\n ...
1
0
['Java']
0
lexicographically-smallest-palindrome
4 ms Beats 62.22%
4-ms-beats-6222-by-bvc01654-n1z0
IntuitionApproachComplexity Time complexity:O(N) Space complexity:O(1) Code
bvc01654
NORMAL
2025-04-09T18:36:47.031966+00:00
2025-04-09T18:36:47.031966+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:O(N) <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity:O(1) <!-- Add your space complexity here, e.g. $$O(n)$$ --> ...
0
0
['C++']
0
lexicographically-smallest-palindrome
Lexicographically Smallest Palindrome
lexicographically-smallest-palindrome-by-fy9j
IntuitionApproachComplexity Time complexity: Space complexity: Code
jyenduri
NORMAL
2025-04-07T18:08:50.653600+00:00
2025-04-07T18:08:50.653600+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
['Go']
0
lexicographically-smallest-palindrome
Simple Java Code using 2 pointer
simple-java-code-using-2-pointer-by-kaly-o5k3
IntuitionApproachComplexity Time complexity: O(n) Space complexity: O(n) Code
kalyanram2053
NORMAL
2025-04-07T12:18:38.351341+00:00
2025-04-07T12:18:38.351341+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: O(n) <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: O(n) <!-- Add your space complexity here, e.g. $$O(n)$$ -->...
0
0
['Java']
0
lexicographically-smallest-palindrome
JAVA TWO POINTER APPROACH
java-two-pointer-approach-by-rohit-baba-cc2u
IntuitionApproachComplexity Time complexity: O(n) Space complexity: O(n) Code
Rohit-Baba
NORMAL
2025-04-05T06:39:22.363653+00:00
2025-04-05T06:39:22.363653+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: O(n) <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: O(n) <!-- Add your space complexity here, e.g. $$O(n)$$ -->...
0
0
['Two Pointers', 'Java']
0
lexicographically-smallest-palindrome
simple solution|| using two pointers
simple-solution-using-two-pointers-by-ko-aojd
IntuitionApproachComplexity Time complexity: Space complexity: Code
kotla_jithendra
NORMAL
2025-03-31T06:44:01.186389+00:00
2025-03-31T06:44:01.186389+00:00
3
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
['Two Pointers', 'String', 'Python3']
0
lexicographically-smallest-palindrome
🔥✅✅ Dart Solution 📌📌 || with Explanation 👌👌
dart-solution-with-explanation-by-nosar-435b
Solution Two-Pointer Technique: We'll use two pointers starting from both ends of the string and move towards the center. Character Comparison: At each step, we
NosaR
NORMAL
2025-03-26T00:57:08.564786+00:00
2025-03-26T00:57:08.564786+00:00
2
false
# Solution 1. **Two-Pointer Technique**: We'll use two pointers starting from both ends of the string and move towards the center. 2. **Character Comparison**: At each step, we compare the characters at both pointers: - If they are different, we need to replace one of them to make them match. - To ensure lexic...
0
0
['Dart']
0
lexicographically-smallest-palindrome
Java, beats 83.93%, 6ms
java-beats-8393-6ms-by-nivet101-9muq
IntuitionIf we have two pointer moving inward from both ends when we encounter different characters, we choose the smaller of the two.Complexity Time complexity
nivet101
NORMAL
2025-03-24T19:05:50.477591+00:00
2025-03-24T19:05:50.477591+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> If we have two pointer moving inward from both ends when we encounter different characters, we choose the smaller of the two. # Complexity - Time complexity:$$O(n)$$ <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity...
0
0
['Java']
0
lexicographically-smallest-palindrome
MinChar solution
minchar-solution-by-ezpectus-i48a
What's a Palindrome?First, a palindrome is a word or phrase that reads the same forwards and backward. For example, "racecar" and "madam" are palindromes.The Pr
ezpectus
NORMAL
2025-03-24T10:39:19.254762+00:00
2025-03-24T10:39:19.254762+00:00
2
false
What's a Palindrome? First, a palindrome is a word or phrase that reads the same forwards and backward. For example, "racecar" and "madam" are palindromes. The Problem: You're given a string s. Your job is to change some of the characters in s so that it becomes a palindrome. But, you want to make the "smallest" pa...
0
0
['Two Pointers', 'String', 'Greedy', 'C++', 'C#']
0
lexicographically-smallest-palindrome
JavaScript, beats 81.44%, 22ms
javascript-beats-8144-22ms-by-nivet101-g5st
IntuitionIf we have two pointer moving inward from both ends when we encounter different characters, we choose the smaller of the two.Complexity Time complexity
nivet101
NORMAL
2025-03-24T02:32:54.977325+00:00
2025-03-24T02:32:54.977325+00:00
6
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> If we have two pointer moving inward from both ends when we encounter different characters, we choose the smaller of the two. # Complexity - Time complexity:$$O(n)$$ <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity...
0
0
['JavaScript']
0
lexicographically-smallest-palindrome
Easy to understand solution in Java. Beats 84.11 %
easy-to-understand-solution-in-java-beat-qlok
Complexity Time complexity: O(n) Space complexity: O(n) Code
Khamdam
NORMAL
2025-03-21T15:42:33.499081+00:00
2025-03-21T15:42:33.499081+00:00
2
false
# Complexity - Time complexity: O(n) - Space complexity: O(n) # Code ```java [] class Solution { public String makeSmallestPalindrome(String s) { char[] chars = s.toCharArray(); int left = 0; int right = chars.length - 1; while (left < right) { if (chars[left] < chars[r...
0
0
['Two Pointers', 'String', 'Java']
0
lexicographically-smallest-palindrome
Optimized simple solution - beats 83.59%🔥
optimized-simple-solution-beats-8359-by-n9lwm
IntuitionApproachComplexity Time complexity: O(N) Space complexity: O(N) Code
cyrusjetson
NORMAL
2025-03-18T11:15:51.510235+00:00
2025-03-18T11:15:51.510235+00:00
4
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: O(N) - Space complexity: O(N) # Code ```java [] class Solution { public String makeSmallestPalindrome(String s) { char[] t = ...
0
0
['Java']
0
lexicographically-smallest-palindrome
C++ | 2 Pointer
c-2-pointer-by-kena7-lva2
Code
kenA7
NORMAL
2025-03-17T13:40:04.263458+00:00
2025-03-17T13:40:04.263458+00:00
3
false
# Code ```cpp [] class Solution { public: string makeSmallestPalindrome(string s) { int i=0,j=s.size()-1; while(i<j) { if(s[i]!=s[j]) { if(s[i]<s[j]) s[j]=s[i]; else s[i]=s[j]; } i++; ...
0
0
['C++']
0
lexicographically-smallest-palindrome
C++ | Simple 0 ms 5 lines solution beats submitted solutions 100% in runtime and 90% in memory
c-simple-0-ms-5-lines-solution-beats-sub-qrwe
IntuitionReplace the twin characters with the smaller one if they are not equal.ApproachParse the string character by character till the mid of the string. Comp
thoka5pointsomeone
NORMAL
2025-03-16T10:21:17.389066+00:00
2025-03-16T10:21:17.389066+00:00
3
false
# Intuition Replace the twin characters with the smaller one if they are not equal. # Approach Parse the string character by character till the mid of the string. Compare each character at a specific position from the beginning with the character at the same position from the end of the string. If the characters are n...
0
0
['C++']
0
lexicographically-smallest-palindrome
Easy and Simple Solution to understand
easy-and-simple-solution-to-understand-b-jkgo
IntuitionA palindrome is a string that reads the same forward and backward. Our goal is to convert the given string into the lexicographically smallest palindro
gane0519
NORMAL
2025-03-15T09:39:02.376521+00:00
2025-03-15T09:39:02.376521+00:00
5
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> A palindrome is a string that reads the same forward and backward. Our goal is to convert the given string into the lexicographically smallest palindrome with minimal modifications. To achieve this, we use a two-pointer approach: 1. Comp...
0
0
['Two Pointers', 'String', 'Java']
0
lexicographically-smallest-palindrome
Simple straight forward two pointers
simple-straight-forward-two-pointers-by-hltto
Code
user9878Nx
NORMAL
2025-03-13T17:18:37.468881+00:00
2025-03-13T17:18:37.468881+00:00
3
false
# Code ```swift [] class Solution { func makeSmallestPalindrome(_ s: String) -> String { var chars = Array(s) var i = 0 var j = chars.count - 1 while i < j { if chars[i] < chars[j] { chars[j] = chars[i] } else { ...
0
0
['Swift']
0
lexicographically-smallest-palindrome
byte performs better than rune
byte-performs-better-than-rune-by-wiiken-vqvd
IntuitionApproachComplexity Time complexity: Space complexity: Code
wiikend
NORMAL
2025-03-07T17:40:33.333889+00:00
2025-03-07T17:40:33.333889+00:00
4
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
['Go']
0
lexicographically-smallest-palindrome
easy to understand
easy-to-understand-by-budu123-p7fj
IntuitionApproachComplexity Time complexity: Space complexity: Code
budu123
NORMAL
2025-03-04T20:07:52.547156+00:00
2025-03-04T20:07:52.547156+00:00
3
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
['C++']
0
lexicographically-smallest-palindrome
Easier way to solve this problem
easier-way-to-solve-this-problem-by-shia-lonv
ApproachFor all mirror-symmetric elements in the string, select the smaller one and use it as a replacement for both. For example, given the string "abcd", we w
ShiaoC
NORMAL
2025-03-02T04:06:03.263408+00:00
2025-03-02T04:06:03.263408+00:00
1
false
# Approach <!-- Describe your approach to solving the problem. --> For all mirror-symmetric elements in the string, select the smaller one and use it as a replacement for both. > For example, given the string "abcd", we will first compare 'a' and 'd', as they are closest to the beginning and end of the string. Since '...
0
0
['C++']
0
lexicographically-smallest-palindrome
Lexicographically Smallest Palindrome Using Two-Pointer Approach
lexicographically-smallest-palindrome-us-hjd5
IntuitionA palindrome is a string that reads the same forward and backward. To transform a given string into a lexicographically smallest palindrome, we need to
rabdya_767
NORMAL
2025-03-01T09:02:43.925248+00:00
2025-03-01T09:02:43.925248+00:00
5
false
--- # **Intuition** A **palindrome** is a string that reads the same forward and backward. To transform a given string into a **lexicographically smallest palindrome**, we need to modify the characters while ensuring minimal changes. A **lexicographically smaller** string means that, when comparing two characters...
0
0
['JavaScript']
0
lexicographically-smallest-palindrome
Lexicographically Smallest Palindrome Transformation
lexicographically-smallest-palindrome-tr-6c8q
IntuitionThe goal is to transform the given string into the lexicographically smallest palindrome by modifying characters as needed. Since a palindrome reads th
rabdya_767
NORMAL
2025-03-01T08:59:02.136845+00:00
2025-03-01T08:59:02.136845+00:00
3
false
--- # **Intuition** The goal is to transform the given string into the **lexicographically smallest palindrome** by modifying characters as needed. Since a palindrome reads the same forward and backward, we can compare corresponding characters from both ends and replace the larger one with the smaller one. --- # *...
0
0
['JavaScript']
0
lexicographically-smallest-palindrome
python code
python-code-by-vishalyadav28-pvlc
ApproachTwo pointer opposite directionComplexity Time complexity: O(N) Space complexity: O(N) Code
vishalyadav28
NORMAL
2025-02-27T09:21:22.377650+00:00
2025-02-27T09:21:22.377650+00:00
5
false
# Approach Two pointer opposite direction # Complexity - Time complexity: $$O(N)$$ - Space complexity: $$O(N)$$ # Code ```python3 [] class Solution: def makeSmallestPalindrome(self, s: str) -> str: # sl = list(s) # left=0 # right=len(sl)-1 # while left<right: # if sl[le...
0
0
['Two Pointers', 'String', 'Python3']
0
lexicographically-smallest-palindrome
java
java-by-shoreshan-7d7r
IntuitionApproachComplexity Time complexity: Space complexity: Code
shoreshan
NORMAL
2025-02-26T23:21:56.173821+00:00
2025-02-26T23:21:56.173821+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
['Java']
0
lexicographically-smallest-palindrome
100% easy solution
100-easy-solution-by-abhinav_gupta0007-8hf8
IntuitionApproachComplexity Time complexity: Space complexity: Code
Abhinav_Gupta0007
NORMAL
2025-02-23T06:07:57.062052+00:00
2025-02-23T06:07:57.062052+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
['C++']
0
lexicographically-smallest-palindrome
simple
simple-by-ryuji-lpde
IntuitionApproachComplexity Time complexity: Space complexity: Code
ryuji
NORMAL
2025-02-22T01:09:14.548209+00:00
2025-02-22T01:09:14.548209+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
['Rust']
0
lexicographically-smallest-palindrome
Very easy to understand-Two pointers
very-easy-to-understand-two-pointers-by-yrncg
IntuitionApproachComplexity Time complexity: Space complexity: Code
lakshmikanth01
NORMAL
2025-02-21T20:15:42.548448+00:00
2025-02-21T20:15:42.548448+00:00
7
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
['Two Pointers', 'String', 'Python3']
0
lexicographically-smallest-palindrome
TRY TO YOUR BEST TO DO YOUR OWN:)
try-to-your-best-to-do-your-own-by-srina-zn11
Code
Srinath_Y
NORMAL
2025-02-20T07:39:29.399280+00:00
2025-02-20T07:39:29.399280+00:00
2
false
# Code ```python [] class Solution(object): def makeSmallestPalindrome(self, s): s=list(s) n=len(s) for i in range(n/2): if s[i]!=s[n-1-i]: if ord(s[i])<ord(s[n-1-i]): s[n-1-i]=s[i] else: s[i]=s[n-1-i] ...
0
0
['String', 'Python']
0
count-number-of-nice-subarrays
[Java/C++/Python] Sliding Window, O(1) Space
javacpython-sliding-window-o1-space-by-l-6tpq
Solution 1: atMost\nHave you read this? 992. Subarrays with K Different Integers\nExactly K times = at most K times - at most K - 1 times\n\n\n# Complexity\nTim
lee215
NORMAL
2019-11-03T04:04:38.512895+00:00
2020-06-15T07:40:04.379933+00:00
92,408
false
# **Solution 1: atMost**\nHave you read this? [992. Subarrays with K Different Integers](https://leetcode.com/problems/subarrays-with-k-different-integers/discuss/523136/JavaC%2B%2BPython-Sliding-Window)\nExactly `K` times = at most `K` times - at most `K - 1` times\n<br>\n\n# **Complexity**\nTime `O(N)` for one pass\n...
590
10
[]
64
count-number-of-nice-subarrays
C++: Visual explanation. O(1) space. Two pointers
c-visual-explanation-o1-space-two-pointe-xbcd
Algorithm\nThe best way to explain this approach is to look at the example:\nLet\'s say k = 2 and we have the following array:\n\n\n\nWe only going to work with
andnik
NORMAL
2020-02-13T21:38:11.823200+00:00
2020-02-19T06:59:46.412712+00:00
25,796
false
##### Algorithm\nThe best way to explain this approach is to look at the example:\nLet\'s say **k = 2** and we have the following array:\n\n![image](https://assets.leetcode.com/users/andnik/image_1582094442.png)\n\nWe only going to work with numbers `1` and `2` because we are only interested in if number is odd or even...
455
3
['C']
33
count-number-of-nice-subarrays
Deque with Picture
deque-with-picture-by-votrubac-p9dz
Intuition\nThis is similar to 992. Subarrays with K Different Integers.\n\nWhen we find k odd numbers, we have one nice subarray, plus an additional subarray fo
votrubac
NORMAL
2019-11-03T05:38:38.885686+00:00
2022-08-04T15:58:59.519948+00:00
17,815
false
#### Intuition\nThis is similar to [992. Subarrays with K Different Integers](https://leetcode.com/problems/subarrays-with-k-different-integers/discuss/235235/C%2B%2BJava-with-picture-prefixed-sliding-window).\n\nWhen we find `k` odd numbers, we have one nice subarray, plus an additional subarray for each even number p...
210
5
['C', 'Java']
25
count-number-of-nice-subarrays
✅Beats 100% -Explained with [ Video ] -C++/Java/Python/JS -Prefix Sum -Interview Solution
beats-100-explained-with-video-cjavapyth-7ett
\n\n# YouTube Video Explanation:\n\n### To watch the video please click on "Watch On Youtube" option available the left bottom corner of the thumbnail.\n\n **I
lancertech6
NORMAL
2024-06-22T00:56:21.994495+00:00
2024-06-22T12:41:41.216007+00:00
33,583
false
![Screenshot 2024-06-22 061620.png](https://assets.leetcode.com/users/images/c80c4521-769c-4e92-be6d-d559d69b7e88_1719017662.3639119.png)\n\n# YouTube Video Explanation:\n\n### To watch the video please click on "Watch On Youtube" option available the left bottom corner of the thumbnail.\n\n<!-- **If you want a video ...
161
2
['Array', 'Hash Table', 'Math', 'Sliding Window', 'Python', 'C++', 'Java', 'JavaScript']
14
count-number-of-nice-subarrays
Subarray Sum Equals K
subarray-sum-equals-k-by-herbert5812-a5a7
If you transform the input array into binary, then the problem becomes the \'Subarray Sum Equals K\' problem. You can think of k odd numbers means sum of then i
herbert5812
NORMAL
2019-11-03T04:37:21.643479+00:00
2019-11-03T04:54:11.287397+00:00
10,762
false
If you transform the input array into binary, then the problem becomes the \'Subarray Sum Equals K\' problem. You can think of k odd numbers means sum of then is k.\n\n```\nclass Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n unordered_map<int, int> m;\n const int n = nums.si...
151
4
['C']
16
count-number-of-nice-subarrays
[Java] PrefixSum 1pass 10line 7ms
java-prefixsum-1pass-10line-7ms-by-wangy-nsuo
At index i, if current odd numbers from the beginning is M,\nand we checked there was N previous index with (M - K) oddnum, then we got N subarrays\nres += N\n\
wangyxwyx
NORMAL
2019-11-03T04:53:28.283787+00:00
2019-11-03T05:12:53.656412+00:00
6,804
false
At index i, if current odd numbers from the beginning is M,\nand we checked there was N previous index with (M - K) oddnum, then we got N subarrays\nres += N\n\n\n```\n public int numberOfSubarrays(int[] nums, int k) {\n int cur = 0, ans = 0;\n Map<Integer, Integer> map = new HashMap<>();\n map....
80
1
[]
11
count-number-of-nice-subarrays
[Prefix Sum & Sliding Window Tutorial] Count Number of Nice Subarrays
prefix-sum-sliding-window-tutorial-count-vll6
This post includes the solution for both using Prexis Sum and Sliding Window.\n\nTopic : Prefix Sum\n\n### Prefix Sum:\nPrefix sum, also known as cumulative su
never_get_piped
NORMAL
2024-06-22T00:20:57.777541+00:00
2024-06-27T07:11:51.997435+00:00
14,886
false
**This post includes the solution for both using Prexis Sum and Sliding Window.**\n\n**Topic** : Prefix Sum\n\n### Prefix Sum:\nPrefix sum, also known as cumulative sum, is a technique used in computer science and mathematics to efficiently calculate the sum of a sequence of numbers. The prefix sum of a sequence `a[0]...
53
1
['Array', 'Hash Table', 'C', 'PHP', 'Prefix Sum', 'Java', 'Go', 'Python3', 'JavaScript']
15
count-number-of-nice-subarrays
[Java/Python 3] 1 pass Sliding Window O(n) time O(1) space w/ brief explanation.
javapython-3-1-pass-sliding-window-on-ti-sy4m
Whenever the count of odd numbers reach k, for each high boundary of the sliding window, we have indexOfLeftMostOddInWin - lowBound options for the low boundary
rock
NORMAL
2019-11-03T04:01:23.903614+00:00
2020-10-17T12:33:12.091462+00:00
7,952
false
1. Whenever the count of odd numbers reach `k`, for each high boundary of the sliding window, we have `indexOfLeftMostOddInWin - lowBound` options for the low boundary, where `indexOfLeftMostOddInWin` is the index of the leftmost odd number within the window, and `lowBound` is the index of the low boundary exclusively;...
48
4
[]
10
count-number-of-nice-subarrays
Python - Two pointer
python-two-pointer-by-harshhx-kyjr
\nclass Solution:\n def numberOfSubarrays(self, nums: List[int], k: int) -> int:\n right ,left = 0,0\n ans = 0 \n odd_cnt = 0\n a
harshhx
NORMAL
2021-06-11T19:01:12.047999+00:00
2021-06-11T19:01:12.048029+00:00
5,163
false
```\nclass Solution:\n def numberOfSubarrays(self, nums: List[int], k: int) -> int:\n right ,left = 0,0\n ans = 0 \n odd_cnt = 0\n ans = 0\n cur_sub_cnt = 0\n for right in range(len(nums)):\n \n if nums[right]%2 == 1:\n odd_cnt += 1\n ...
41
0
['Two Pointers', 'Python', 'Python3']
9
count-number-of-nice-subarrays
easy peasy python solution with explanation
easy-peasy-python-solution-with-explanat-x0e6
\t# Just keep count of the current odd number.\n\t# Look in the dictionary if we can find (currendOds - k), \n\t# if it exisits that means I can get an subarray
lostworld21
NORMAL
2019-11-03T18:31:51.327405+00:00
2019-11-04T15:36:06.568313+00:00
5,465
false
\t# Just keep count of the current odd number.\n\t# Look in the dictionary if we can find (currendOds - k), \n\t# if it exisits that means I can get an subarray with k odds.\n\t# Also keep count of number of different types of odds too,\n\t# because for K =1 , [2,2,1] is a valid list, so does, [2,1] and [1].\n\t\n ...
36
1
['Python', 'Python3']
8
count-number-of-nice-subarrays
C++ || Two Pointers || Clean Code
c-two-pointers-clean-code-by-jennifer-kf21
\nclass Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n int n = nums.size();\n int ans = 0,odd = 0,cnt = 0;\n
Jennifer__
NORMAL
2022-08-25T10:50:59.088068+00:00
2022-08-25T10:50:59.088100+00:00
4,258
false
```\nclass Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n int n = nums.size();\n int ans = 0,odd = 0,cnt = 0;\n int l = 0,r = 0;\n while(r<n)\n {\n if(nums[r]%2 != 0)\n {\n odd++;\n cnt = 0;\n ...
32
0
['Two Pointers', 'C', 'Sliding Window']
3
count-number-of-nice-subarrays
JAVA | Sliding Window
java-sliding-window-by-aman0786khan-2dt8
\nclass Solution {\n public int numberOfSubarrays(int[] nums, int k) {\n int oddcount=0;\n int res=0;\n int i=0;\n int count=0;\n
aman0786khan
NORMAL
2021-07-04T10:09:41.445090+00:00
2021-07-04T10:09:41.445122+00:00
2,351
false
```\nclass Solution {\n public int numberOfSubarrays(int[] nums, int k) {\n int oddcount=0;\n int res=0;\n int i=0;\n int count=0;\n for(int j=0;j<nums.length;j++){\n if(nums[j]%2==1){\n oddcount++;\n count=0;\n }\n whi...
30
0
[]
4
count-number-of-nice-subarrays
java || sliding window || two pinter
java-sliding-window-two-pinter-by-ankurj-3bhh
\nclass Solution {\n public int numberOfSubarrays(int[] nums, int k) {\n int i=0;\n int j=0;\n int oddCount=0;\n int count=0;\n
ANKURJANA-1
NORMAL
2022-08-29T13:06:11.568062+00:00
2022-08-29T13:06:11.568103+00:00
4,309
false
```\nclass Solution {\n public int numberOfSubarrays(int[] nums, int k) {\n int i=0;\n int j=0;\n int oddCount=0;\n int count=0;\n int temp=0;\n \n while(j<nums.length){\n if(nums[j]%2==1){\n oddCount++;\n temp=0;\n ...
27
0
['Sliding Window', 'Java']
6
count-number-of-nice-subarrays
Prefix sum+Sliding window vs at most k odds||35ms Beats 99.99%
prefix-sumsliding-window-vs-at-most-k-od-bz7i
Intuition\n Describe your first thoughts on how to solve this problem. \nThe concept is to use sliding window. With the help of prefix sum, it made an acceptibl
anwendeng
NORMAL
2024-06-22T02:09:04.411473+00:00
2024-06-22T06:00:05.777780+00:00
4,366
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe concept is to use sliding window. With the help of prefix sum, it made an acceptible solution.\n\n2nd approach usse at most k odds argument which is applied to solve the hard question [992. Subarrays with K Different Integers](https:/...
26
5
['Array', 'Sliding Window', 'Prefix Sum', 'C++']
5
count-number-of-nice-subarrays
Detailed Explanation | One Pass, O(1) Space - C++, Python, Java
detailed-explanation-one-pass-o1-space-c-odm5
Approach\n Describe your approach to solving the problem. \nOur goal is to count the number of sub arrays that have exactly k odd numbers. Let\'s take a look at
not_yl3
NORMAL
2024-06-22T00:31:44.387493+00:00
2024-06-22T02:18:27.734937+00:00
6,024
false
# Approach\n<!-- Describe your approach to solving the problem. -->\nOur goal is to count the number of sub arrays that have exactly `k` odd numbers. Let\'s take a look at Example 3 where `k = 2` (but I added an extra 1 to the end):\n\n`nums = [2,2,2,1,2,2,1,2,2,2,1]`\n\nOur first nice subarray starts at index 7 since ...
26
0
['Array', 'Math', 'C', 'Sliding Window', 'C++', 'Java', 'Python3']
7
count-number-of-nice-subarrays
C++ || 3 APPROACHES || SOLUTION
c-3-approaches-solution-by-_himanshu_12-b977
\nclass Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n int i=0;\n int j=0;\n int count=0;\n int result
_himanshu_12
NORMAL
2022-09-11T06:48:10.429934+00:00
2022-09-11T06:48:10.429968+00:00
5,382
false
```\nclass Solution {\npublic:\n int numberOfSubarrays(vector<int>& nums, int k) {\n int i=0;\n int j=0;\n int count=0;\n int result=0;\n int first_occur=0;\n vector<int>occur(nums.size(),0);\n int index=0;\n int current=0;\n // Variable window size prob...
26
2
['C', 'Sliding Window', 'Prefix Sum', 'C++']
5
count-number-of-nice-subarrays
C++| 🚀 ✅ Sliding Window | 🚀 ✅ With Explaination | 🚀 ✅ Easy to Understand
c-sliding-window-with-explaination-easy-kuve5
Intuition:\r\nThe problem requires finding the number of subarrays having exactly k odd integers. We can solve the problem using sliding window technique where
devanshupatel
NORMAL
2023-04-11T15:12:40.847989+00:00
2023-04-14T14:15:44.875906+00:00
6,576
false
# Intuition:\r\nThe problem requires finding the number of subarrays having exactly k odd integers. We can solve the problem using sliding window technique where we maintain a window of contiguous subarray and slide it from left to right. While sliding the window, we keep track of the number of odd integers inside the ...
24
0
['Sliding Window', 'C++']
4
count-number-of-nice-subarrays
Easy C++ Solution || T.C = O(N) || Sliding Window
easy-c-solution-tc-on-sliding-window-by-k1yie
Intuition\r\nTo solve the problem of counting the number of subarrays with exactly k odd numbers, we can use a sliding window approach. This method allows us to
kumar_kshitij
NORMAL
2024-06-22T00:07:55.227272+00:00
2024-06-22T00:07:55.227288+00:00
5,418
false
# Intuition\r\nTo solve the problem of counting the number of subarrays with exactly `k` odd numbers, we can use a sliding window approach. This method allows us to efficiently manage the window of elements in the array and count the number of valid subarrays without needing to recompute for each possible subarray.\r\n...
21
0
['Sliding Window', 'C++']
6
count-number-of-nice-subarrays
C++ Sliding Window Solution O(1) Space
c-sliding-window-solution-o1-space-by-ro-oj38
Similar to https://leetcode.com/problems/subarrays-with-k-different-integers/\n\npublic:\n int numarr(vector<int>&nums,int k){\n int ans=0;\n i
rom111
NORMAL
2020-09-02T09:28:59.954373+00:00
2020-09-02T09:28:59.954413+00:00
3,036
false
Similar to https://leetcode.com/problems/subarrays-with-k-different-integers/\n```\npublic:\n int numarr(vector<int>&nums,int k){\n int ans=0;\n int count=0;\n int i=0,j=0,n=nums.size();\n while(j<n){\n if(nums[j]%2==1){\n count++;\n }\n if(...
21
1
[]
2
count-number-of-nice-subarrays
nice subarrays || c++ || easy
nice-subarrays-c-easy-by-sheetaljoshi-nkhd
//exactly similar to the problem:subarrays sum equal to given sum(k)\n// we just need to convert odds with 1 and even with 0\n//and find the given sub arrays ha
sheetaljoshi
NORMAL
2021-11-28T06:52:27.358079+00:00
2021-11-28T07:23:36.312548+00:00
2,051
false
//exactly similar to the problem:subarrays sum equal to given sum(k)\n// we just need to convert odds with 1 and even with 0\n//and find the given sub arrays having sum k\nUPVOTE IF YOU GET:)\n```\nclass Solution {\npublic:\n \n int numberOfSubarrays(vector<int>& a, int k) {\n int ans=0,sum=0,n=a.size();\n...
17
1
['C', 'C++']
4
count-number-of-nice-subarrays
C++ Prefix State Map / Two Pointers / Sliding Window
c-prefix-state-map-two-pointers-sliding-31ara
See my latest update in repo LeetCode\n\n## Solution 1. Prefix State Map\n\nUse a map m to store the mapping from the count of odd numbers cnt to the first inde
lzl124631x
NORMAL
2021-10-11T04:34:14.057512+00:00
2021-10-11T04:34:14.057565+00:00
2,491
false
See my latest update in repo [LeetCode](https://github.com/lzl124631x/LeetCode)\n\n## Solution 1. Prefix State Map\n\nUse a map `m` to store the mapping from the count of odd numbers `cnt` to the first index in the array that has `cnt` numbers in front of it and including itself.\n\nWhen `cnt >= k`, we add `m[cnt - k +...
17
0
[]
1
count-number-of-nice-subarrays
Python Solution Prefix Sum
python-solution-prefix-sum-by-yuyingji-xy2h
\ndef numberOfSubarrays(self, nums, k):\n """\n :type nums: List[int]\n :type k: int\n :rtype: int\n """\n res = 0\n
yuyingji
NORMAL
2019-11-03T04:03:16.509603+00:00
2019-11-03T18:38:39.962951+00:00
3,257
false
```\ndef numberOfSubarrays(self, nums, k):\n """\n :type nums: List[int]\n :type k: int\n :rtype: int\n """\n res = 0\n count = 0\n prefix = {}\n prefix[0] = 1\n for i in range(len(nums)):\n \n if nums[i] % 2 != 0:\n ...
17
2
[]
7
count-number-of-nice-subarrays
💹Easy 3 Approaches 🔰📊|| Beats 98% || 🚀 Hashing and Two Pointers 🎯|| In Depth
easy-3-approaches-beats-98-hashing-and-t-mf1e
\r\n# Intuition:\r\nThe problem is essentially about finding subarrays with exactly \'k\' odd numbers. \r\nWe can use a hashmap to count the occurrences of pref
laggerk
NORMAL
2024-06-22T07:13:49.400576+00:00
2024-06-22T07:13:49.400621+00:00
2,836
false
\r\n# Intuition:\r\nThe problem is essentially about finding subarrays with exactly \'k\' odd numbers. \r\nWe can use a hashmap to count the occurrences of prefix sums, which helps us keep track \r\nof the number of odd numbers encountered so far.\r\n \r\n# Approach 1:\r\n1. Initialize a hashmap to store the count of p...
16
1
['Array', 'Hash Table', 'Math', 'Sliding Window', 'Python', 'C++', 'Java', 'Python3']
3
count-number-of-nice-subarrays
JAVA || Picture + Detail Explanation || prefix sum + HashMap || Easy Solution
java-picture-detail-explanation-prefix-s-gpyl
\n\n In this problem , First we will change the odd digit from 1 and even with zero in given array.\n then we use the same approach which we used in the leetcod
ayushx
NORMAL
2021-10-20T20:45:56.983692+00:00
2021-11-02T18:23:57.601451+00:00
2,988
false
![image](https://assets.leetcode.com/users/images/27b0cd6e-ffd3-4eca-8787-6b8d0b15b43f_1634763142.2267573.png)\n\n* In this problem , First we will change the odd digit from 1 and even with zero in given array.\n* then we use the same approach which we used in the leetcode problem 560. If you want detail explanation th...
15
2
['Sliding Window', 'Prefix Sum', 'Java']
5
count-number-of-nice-subarrays
Java Solution
java-solution-by-credit_card-lcab
Replace all odd numbers with 1 and even with zeroes\n\nNow the problem becomes\nhttps://leetcode.com/problems/subarray-sum-equals-k/\n\nFind number of sub arrys
credit_card
NORMAL
2020-09-06T14:15:24.362308+00:00
2020-10-04T14:53:12.707737+00:00
1,295
false
Replace all odd numbers with 1 and even with zeroes\n\nNow the problem becomes\n[https://leetcode.com/problems/subarray-sum-equals-k/](https://leetcode.com/problems/subarray-sum-equals-k/)\n\nFind number of sub arrys with sum = K\n```\npublic int numberOfSubarrays(int[] nums, int k) {\n //Replace all odd by 1 a...
15
0
[]
3
count-number-of-nice-subarrays
✅ One Line Solution
one-line-solution-by-mikposp-gv5a
(Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)Code #1.1 - One LineTime complexity: O(n). Space com
MikPosp
NORMAL
2024-06-22T09:18:33.601994+00:00
2025-02-11T10:52:26.574263+00:00
1,323
false
(Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly) # Code #1.1 - One Line Time complexity: $$O(n)$$. Space complexity: $$O(n)$$. ``` class Solution: def numberOfSubarrays(self, a: List[int], k: int) -> int: return (z:=Counter([q:=0])) and sum(z.upda...
14
0
['Array', 'Hash Table', 'Math', 'Prefix Sum', 'Python', 'Python3']
1
count-number-of-nice-subarrays
Sliding window
sliding-window-by-anil-budamakuntla-kvga
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
ANIL-BUDAMAKUNTLA
NORMAL
2024-06-22T00:33:52.290783+00:00
2024-06-22T00:33:52.290808+00:00
1,237
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. $$O...
14
0
['Array', 'Sliding Window', 'C++']
5
count-number-of-nice-subarrays
C++ Sliding Window Solution + Probability Rule O(N)
c-sliding-window-solution-probability-ru-v1vg
Runtime: 112 ms, faster than 93.17% of C++ online submissions for Count Number of Nice Subarrays.\nMemory Usage: 67.5 MB, less than 91.98% of C++ online submiss
ahsan83
NORMAL
2021-07-11T15:57:15.687238+00:00
2021-07-11T17:26:57.770515+00:00
1,880
false
Runtime: 112 ms, faster than 93.17% of C++ online submissions for Count Number of Nice Subarrays.\nMemory Usage: 67.5 MB, less than 91.98% of C++ online submissions for Count Number of Nice Subarrays.\n\n```\nInorder to solve the problem we can easily find the main subarray containing K odd numbers using Sliding\nWindo...
14
0
['Array', 'C', 'Sliding Window', 'Probability and Statistics']
3
count-number-of-nice-subarrays
C++ : Sliding Window || Two pointers || O(n) Space
c-sliding-window-two-pointers-on-space-b-n2j4
This question is slightly based on sliding window, however one needs proper idea of whats going on.\nWe actually just need to maintain the condition of (Oddnumb
nivedita_chatterjee_021
NORMAL
2022-02-13T14:44:46.111529+00:00
2022-02-13T14:44:46.111556+00:00
2,206
false
This question is slightly based on sliding window, however one needs proper idea of whats going on.\nWe actually just need to maintain the condition of (Oddnumbers==k), once we get it equal.\nTill the time our odd number count is less than k, we just simply keep updating **"end"**.\nOnce our oddnum count is equal to k,...
13
0
['Two Pointers', 'C', 'Sliding Window', 'C++']
2