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
reverse-prefix-of-word
C++ BEST SOLUTION
c-best-solution-by-poxyprabal-9bps
\n\n# Code\n\nclass Solution {\npublic:\n string reversePrefix(string word, char ch) {\n int l = 0;\n for (int r = 0; r < word.size(); r++) {\n
poxyprabal
NORMAL
2024-05-01T16:18:34.467264+00:00
2024-05-01T16:18:34.467285+00:00
385
false
\n\n# Code\n```\nclass Solution {\npublic:\n string reversePrefix(string word, char ch) {\n int l = 0;\n for (int r = 0; r < word.size(); r++) {\n if (word[r] == ch) {\n while (l <= r) {\n swap(word[r], word[l]);\n l++;\n ...
4
0
['C++']
0
reverse-prefix-of-word
Simple easy to understand solution in 0ms.
simple-easy-to-understand-solution-in-0m-gkeu
Intuition\nMy intition was to count the index of character and then reverse it to that index using a reverse function.\n\n# Approach\nfind the index of characte
ayushsachan7
NORMAL
2024-05-01T10:02:09.668166+00:00
2024-05-01T10:02:09.668194+00:00
309
false
# Intuition\nMy intition was to count the index of character and then reverse it to that index using a reverse function.\n\n# Approach\nfind the index of character using for loop and reverse upto that index using swap function.\n\n# Complexity\n- Time complexity: O(N)\n\n- Space complexity: O(1)\n\n# Code\n```\nclass S...
4
0
['Two Pointers', 'String', 'C++']
4
reverse-prefix-of-word
EXPLAINED SOLUTION
explained-solution-by-nurliaidin-ys5p
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n1. Prepare to Store Pre
Nurliaidin
NORMAL
2024-05-01T09:54:25.042058+00:00
2024-05-01T09:54:25.042078+00:00
532
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. **Prepare to Store Prefix and Suffix:**\n - Initialize `pre` to store characters before `ch`.\n - Set up `suf` to store any characters after `ch`.\n\n2. **Searc...
4
0
['C++', 'JavaScript']
3
reverse-prefix-of-word
String find/reverse solution
string-findreverse-solution-by-drgavriko-0q8p
Approach\n Describe your approach to solving the problem. \n\nFirst, we find the position of the first occurrence of the character \'ch\' in the string \'word\'
drgavrikov
NORMAL
2024-05-01T07:10:31.463305+00:00
2024-05-01T07:11:00.476863+00:00
10
false
# Approach\n<!-- Describe your approach to solving the problem. -->\n\nFirst, we find the position of the first occurrence of the character \'ch\' in the string \'word\' using the \'find\' function.\n\nIf the character is found (i.e., its index is not equal to std::string::npos), we use the \'std::reverse\' function fr...
4
0
['C++']
0
reverse-prefix-of-word
Easy solution and iterative solution
easy-solution-and-iterative-solution-by-3iwig
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nIterative approach\nYou
Rishabhdwivedii
NORMAL
2024-05-01T04:49:08.416858+00:00
2024-05-01T04:49:08.416879+00:00
541
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nIterative approach\nYou define a function reversePrefix that takes a string word and a character ch as input parameters and returns a string.\nYou initialize an empty ...
4
0
['Python3']
4
reverse-prefix-of-word
easiest approach cpp |
easiest-approach-cpp-by-ankitlodhi-3y6i
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
ankitlodhi
NORMAL
2024-05-01T04:14:16.693785+00:00
2024-05-01T04:14:16.693819+00:00
342
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)$$ --...
4
0
['C++']
0
reverse-prefix-of-word
The solution really easy to got it
the-solution-really-easy-to-got-it-by-ja-sayw
Code\n\nfunc reversePrefix(word string, ch byte) string {\n var natija string\n for i := 0; i < len(word); i++ {\n if word[i] == ch { \n
Javohir_hasanov
NORMAL
2024-05-01T03:59:40.744903+00:00
2024-05-01T03:59:40.744933+00:00
218
false
# Code\n```\nfunc reversePrefix(word string, ch byte) string {\n var natija string\n for i := 0; i < len(word); i++ {\n if word[i] == ch { \n ch_index := i\n for i >= 0 {\n natija += string(word[i])\n i--\n } \n return natija + word[...
4
0
['Go']
2
reverse-prefix-of-word
💯Two Pointers🎯✅ | 98.63%🔥| 4 Easy Steps : 🎯| Simple (5 line) to understand💯Explained
two-pointers-9863-4-easy-steps-simple-5-4rrkd
Intuition\nsimply we are using 2\uFE0F\u20E3 pointers\uD83D\uDC96\uD83D\uDC96 left and right to traverse pointer in opposite direction and concurrently swaping
Prathamesh18X
NORMAL
2024-05-01T03:34:04.908921+00:00
2024-05-01T03:34:04.908946+00:00
1,005
false
# Intuition\nsimply we are using **2\uFE0F\u20E3 pointers**\uD83D\uDC96\uD83D\uDC96 `left` and `right` to traverse pointer in opposite direction and concurrently swaping each other to reverse the string till `left` is less than `right`...\uD83D\uDCAF\n\n# Dont forget to vote...\u2B06\uFE0F **me**\uD83E\uDD73\n### *and*...
4
0
['Two Pointers', 'String', 'C', 'Python', 'C++', 'Java', 'Python3', 'Ruby', 'Kotlin', 'JavaScript']
3
reverse-prefix-of-word
✅Beats 91%🔥 2 Solutions🔥🔥🔥Simple character matching solution. With no additional space
beats-91-2-solutionssimple-character-mat-cly4
image.png\n\n\n# Intuition\nIf we can find the given charater ch in given string word, we have to reverse string till first ch including it. To do this, we can
Saketh3011
NORMAL
2024-05-01T01:31:10.330068+00:00
2024-05-01T07:01:33.198804+00:00
632
false
image.png\n![image.png](https://assets.leetcode.com/users/images/8c43913b-117c-4e20-8b5f-6c531b78710f_1714525471.4359238.png)\n\n# Intuition\nIf we can find the given charater `ch` in given string `word`, we have to reverse string till first `ch` including it. To do this, we can find first `ch` index in `word` and then...
4
0
['Two Pointers', 'String', 'C', 'Python', 'C++', 'Java', 'Python3']
1
reverse-prefix-of-word
Java || 100% beats
java-100-beats-by-saurabh_kumar1-h12l
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
saurabh_kumar1
NORMAL
2023-08-16T11:06:03.444839+00:00
2023-08-16T11:06:03.444864+00:00
80
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:0(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:0(1)\n<!-- Add your space complexity here, e.g. $$O...
4
0
['Java']
1
reverse-prefix-of-word
[ Go Solution ]Great explanation and Full Description
go-solution-great-explanation-and-full-d-8zrr
Intuition\nThe problem asks to reverse the prefix of a string up to the first occurrence of a specified character. If the character does not exist in the string
sansaian
NORMAL
2023-06-21T14:34:16.549695+00:00
2023-06-21T14:34:16.549721+00:00
454
false
# Intuition\nThe problem asks to reverse the prefix of a string up to the first occurrence of a specified character. If the character does not exist in the string, we should return the original string. The problem can be solved by iterating through the string and once we find the specified character, we reverse the pre...
4
0
['Two Pointers', 'Go']
0
reverse-prefix-of-word
reverse prefix python3
reverse-prefix-python3-by-timsmyrnov-cy41
Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(N)\n\n# Code\n\nclass Solution:\n def reversePrefix(self, word: str, ch: str) -> str:\n
timsmyrnov
NORMAL
2023-05-01T07:40:58.023315+00:00
2023-05-01T07:40:58.023348+00:00
717
false
# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(N)\n\n# Code\n```\nclass Solution:\n def reversePrefix(self, word: str, ch: str) -> str:\n prefix = \'\'\n for i, c in enumerate(word):\n if c == ch:\n return (prefix + c)[::-1] + word[i+1:]\n prefix +...
4
0
['Python3']
2
reverse-prefix-of-word
Sol: Reverse Prefix of Word [JAVA]
sol-reverse-prefix-of-word-java-by-subha-glbe
Code\n\nclass Solution {\n public String reversePrefix(String word, char ch) {\n String subString = word.substring(0, word.indexOf(ch)+1);\n\t\tString
subhajitbhattacharjee007
NORMAL
2022-12-28T12:18:56.394869+00:00
2022-12-28T12:19:13.747449+00:00
371
false
# Code\n```\nclass Solution {\n public String reversePrefix(String word, char ch) {\n String subString = word.substring(0, word.indexOf(ch)+1);\n\t\tString remainingString = word.substring( word.indexOf(ch)+1, word.length());\n\t\tString s = "";\n\t\tfor( int i=subString.length()-1; i>=0; i--) {\n\t\t\ts=s+s...
4
0
['Java']
2
reverse-prefix-of-word
C++ | Find and Reverse | Easy
c-find-and-reverse-easy-by-shreyanshxyz-kvb3
\nclass Solution {\npublic:\n string reversePrefix(string word, char ch) {\n if(word.length() == 1) return word;\n \n for(int i = 0; i <
shreyanshxyz
NORMAL
2022-08-10T13:50:38.788842+00:00
2022-08-10T13:50:38.788883+00:00
239
false
```\nclass Solution {\npublic:\n string reversePrefix(string word, char ch) {\n if(word.length() == 1) return word;\n \n for(int i = 0; i < word.size(); i++){\n if(word[i] == ch){\n reverse(word.begin(), word.begin() + i + 1);\n break;\n }\n ...
4
0
['C']
0
reverse-prefix-of-word
C++ solution || 2 approaches || Solved using Stack(3ms) || using reverse function(0ms)
c-solution-2-approaches-solved-using-sta-ttv8
\t\t\t\t\t\t\t\t\t----Approach 1(Stack)----\n\n\tclass Solution {\n\tpublic:\n\t\tstring reversePrefix(string word, char ch) {\n\n stack s;\n int
ap00rv_13
NORMAL
2022-07-08T04:00:56.179367+00:00
2022-07-08T04:00:56.179398+00:00
254
false
\t\t\t\t\t\t\t\t\t----Approach 1(Stack)----\n\n\tclass Solution {\n\tpublic:\n\t\tstring reversePrefix(string word, char ch) {\n\n stack<char> s;\n int i=0, count = 0;\n int size = word.size();\n\n while(word[i] != ch){\n count++;\n if(count == size) return ...
4
0
['Stack', 'C', 'C++']
1
reverse-prefix-of-word
c++ simple one line code
c-simple-one-line-code-by-sailakshmi1-0x70
```\nclass Solution {\npublic:\n string reversePrefix(string word, char ch) {\n int j=0;\n for(int i=0;i<word.size();i++){\n if(word[i]=
sailakshmi1
NORMAL
2022-06-18T08:41:16.997662+00:00
2022-06-18T08:41:16.997703+00:00
251
false
```\nclass Solution {\npublic:\n string reversePrefix(string word, char ch) {\n int j=0;\n for(int i=0;i<word.size();i++){\n if(word[i]==ch){\n reverse(word.begin(),word.begin()+i+1);\n break;\n }\n }\n return word;\n }\n};
4
0
['C']
1
reverse-prefix-of-word
Python 3 (25ms) | One Line Solution | Faster than 95% | Easy to Understand
python-3-25ms-one-line-solution-faster-t-6sla
\nclass Solution:\n def reversePrefix(self, word: str, ch: str) -> str:\n if ch not in word:\n return word\n return (\'\'.join(rever
MrShobhit
NORMAL
2022-01-25T17:24:59.420287+00:00
2022-01-25T17:24:59.420331+00:00
545
false
```\nclass Solution:\n def reversePrefix(self, word: str, ch: str) -> str:\n if ch not in word:\n return word\n return (\'\'.join(reversed(word[:(word.index(ch)+1)]))+word[(word.index(ch))+1:])\n```
4
0
['String', 'Python', 'Python3']
4
reverse-prefix-of-word
[JavaScript] one line solution (86%,35%)
javascript-one-line-solution-8635-by-053-xz0d
Runtime: 76 ms, faster than 86.18% of JavaScript online submissions for Reverse Prefix of Word.\nMemory Usage: 38.9 MB, less than 35.53% of JavaScript online su
0533806
NORMAL
2021-09-15T02:25:40.756831+00:00
2021-09-15T02:25:40.756869+00:00
641
false
Runtime: 76 ms, faster than 86.18% of JavaScript online submissions for Reverse Prefix of Word.\nMemory Usage: 38.9 MB, less than 35.53% of JavaScript online submissions for Reverse Prefix of Word.\n```\nvar reversePrefix = function(word, ch) {\n return word.indexOf(ch) !== -1 ? word.split("").slice(0, word.indexOf(...
4
0
['JavaScript']
2
reverse-prefix-of-word
C++ Simple and Easy 2-Line Solution, 0ms Faster than 100%
c-simple-and-easy-2-line-solution-0ms-fa-q8ym
We find the index of the first accurance of the char in word, then we use built-in function reverse which accepts a range to reverse.\n\nclass Solution {\npubli
yehudisk
NORMAL
2021-09-13T14:34:55.396312+00:00
2021-09-13T14:34:55.396354+00:00
192
false
We find the index of the first accurance of the char in word, then we use built-in function `reverse` which accepts a range to reverse.\n```\nclass Solution {\npublic:\n string reversePrefix(string word, char ch) {\n reverse(word.begin(), word.begin() + word.find(ch) + 1);\n return word;\n }\n};\n``...
4
0
['C']
0
reverse-prefix-of-word
Python 3, straightforward
python-3-straightforward-by-silvia42-pwo9
We are iterating over the string word until character ch is found.\nWe return reversed slice plus leftover from the string word.\n\nclass Solution:\n def rev
silvia42
NORMAL
2021-09-12T04:05:37.842968+00:00
2021-09-12T05:37:15.328076+00:00
357
false
We are iterating over the string ```word``` until character ```ch``` is found.\nWe return reversed slice plus leftover from the string ```word```.\n```\nclass Solution:\n def reversePrefix(self, word: str, ch: str) -> str:\n for i in range(len(word)):\n if word[i]==ch:\n return word[...
4
1
[]
2
reverse-prefix-of-word
beats 100% simple solution
beats-100-simple-solution-by-harshjat-x8uy
IntuitionThe problem requires reversing the prefix of the given string word up to the first occurrence of the character ch. A natural approach is to iterate thr
harshjat
NORMAL
2025-03-03T09:46:42.869870+00:00
2025-03-03T09:46:42.869870+00:00
49
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> The problem requires reversing the prefix of the given string word up to the first occurrence of the character ch. A natural approach is to iterate through the string, identify the first occurrence of ch, and reverse the substring from the ...
3
0
['C++']
0
reverse-prefix-of-word
Real Solution using stack
real-solution-using-stack-by-piero24-r8h8
Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(n)\n\n# Code\npython3 []\nclass Solution:\n def reversePrefix(self, word: str, ch: str) -> str:\
Piero24
NORMAL
2024-09-27T13:48:54.903768+00:00
2024-09-27T13:48:54.903788+00:00
142
false
# Complexity\n- Time complexity: $$O(n)$$\n\n- Space complexity: $$O(n)$$\n\n# Code\n```python3 []\nclass Solution:\n def reversePrefix(self, word: str, ch: str) -> str:\n head, stack = "", []\n for i, e in enumerate(word):\n if e == ch:\n head = e\n word = word...
3
0
['Stack', 'C++', 'Java', 'Python3']
0
reverse-prefix-of-word
Beats 100.00% of users with C++ || Step By Step Explain || Easy To Understand ||
beats-10000-of-users-with-c-step-by-step-8e05
Abhiraj Pratap Singh\n\n---\n\n# if you like the solution please UPVOTE it....\n\n\n---\n\n# Intuition\n- The problem seems to involve reversing a substring of
abhirajpratapsingh
NORMAL
2024-05-02T16:59:15.122512+00:00
2024-05-02T16:59:15.122546+00:00
13
false
# Abhiraj Pratap Singh\n\n---\n\n# if you like the solution please UPVOTE it....\n\n\n---\n\n# Intuition\n- The problem seems to involve reversing a substring of a given string starting from the beginning up to the occurrence of a specified character.\n\n---\n\n![1713037055032.png](https://assets.leetcode.com/users/ima...
3
0
['Two Pointers', 'String', 'C++']
0
reverse-prefix-of-word
Reverse prefix of word cpp soltuion 0ms run time
reverse-prefix-of-word-cpp-soltuion-0ms-qv7bh
\n\n\n\n# Intuition\nThis problem involves reversing a substring of a given string up to a specified character. The intuition here is to iterate through the str
Pratham_2521
NORMAL
2024-05-01T08:10:08.842448+00:00
2024-05-01T08:10:08.842480+00:00
30
false
\n[![Screenshot 2024-05-01 133721.png](https://assets.leetcode.com/users/images/fca8f24e-e357-49ac-82c5-189501735693_1714550888.3303463.png)](https://leetcode.com/problems/reverse-prefix-of-word/submissions/1246206292/)\n\n\n# Intuition\nThis problem involves reversing a substring of a given string up to a specified ch...
3
0
['C++']
2
reverse-prefix-of-word
✅Simple Solution || Multiple Approach || Easy Explanation || Beginner Friendly🔥🔥🔥
simple-solution-multiple-approach-easy-e-h0gv
Intuition\nThe intuition behind this solution is to reverse the prefix of the given string word up to the first occurrence of the character ch. If the character
Sayan98
NORMAL
2024-05-01T06:52:06.467123+00:00
2024-05-02T05:44:56.251013+00:00
246
false
# Intuition\nThe intuition behind this solution is to reverse the prefix of the given string word up to the first occurrence of the character ch. If the character ch is not present in the string, the entire string is returned unchanged.\n\n# Approach\n- Find the **index** of the first occurrence of the character ch in ...
3
0
['Two Pointers', 'String', 'C#']
1
reverse-prefix-of-word
Beats 100% C++ solution | with explanantion
beats-100-c-solution-with-explanantion-b-okxg
Approach\n- Iterate over input string till we find required character.\n- Store and reverse string till current index\n- Return by adding it with remaining stri
anupsingh556
NORMAL
2024-05-01T06:51:12.135148+00:00
2024-05-01T06:51:39.546433+00:00
5
false
# Approach\n- Iterate over input string till we find required character.\n- Store and reverse string till current index\n- Return by adding it with remaining string\n- If no occurence is found we can simply return original string\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n# Code\n```\nclass...
3
0
['C++']
0
reverse-prefix-of-word
Python | Easy
python-easy-by-khosiyat-f9pt
see the Successfully Accepted Submission\n\n# Code\n\nclass Solution:\n def reversePrefix(self, word: str, ch: str) -> str:\n index = word.find(ch) #
Khosiyat
NORMAL
2024-05-01T06:48:40.875554+00:00
2024-05-01T06:48:40.875591+00:00
362
false
[see the Successfully Accepted Submission](https://leetcode.com/problems/reverse-prefix-of-word/submissions/1246310040/?source=submission-ac)\n\n# Code\n```\nclass Solution:\n def reversePrefix(self, word: str, ch: str) -> str:\n index = word.find(ch) # Find the index of the first occurrence of ch\n i...
3
0
['Python3']
1
reverse-prefix-of-word
Best Solution || Beats 100% || Simplified Approach || O(n) || C++ ||
best-solution-beats-100-simplified-appro-gbhd
# Intuition \n\n\n# Approach\n\n\n\nThe approach of the provided code is to reverse the prefix of a given string up to the first occurrence of a specific char
atharvviit
NORMAL
2024-05-01T06:34:50.696515+00:00
2024-05-01T06:34:50.696546+00:00
116
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\nThe approach of the provided code is to reverse the prefix of a given string up to the first occurrence of a specific character. Here\'s a step-by-step br...
3
0
['Two Pointers', 'String', 'C++', 'Java']
0
reverse-prefix-of-word
Easy to understand solution CPP, Java and Python
easy-to-understand-solution-cpp-java-and-sk7k
Intuition\n Describe your first thoughts on how to solve this problem. \nApply brute force i.e, do as you are asked to do \n\n# Approach\n Describe your approac
Harshit_PSIT
NORMAL
2024-05-01T05:14:15.187369+00:00
2024-05-01T05:14:15.187401+00:00
687
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nApply brute force i.e, do as you are asked to do \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nAlgrithm to be performed-:\n- Find the index of the given character in the word string\n- Generate a substring from ...
3
0
['Two Pointers', 'String', 'Python', 'C++', 'Java', 'Python3']
0
reverse-prefix-of-word
✅ Simple 3 line solution beat 100% 🚀
simple-3-line-solution-beat-100-by-cs_ba-335x
Code\n\nclass Solution {\npublic:\n string reversePrefix(string word, char ch) {\n int ind = word.find(ch);\n if (ind >= word.size())\n
cs_balotiya
NORMAL
2024-05-01T04:30:51.316661+00:00
2024-05-01T04:31:15.930088+00:00
9
false
# Code\n```\nclass Solution {\npublic:\n string reversePrefix(string word, char ch) {\n int ind = word.find(ch);\n if (ind >= word.size())\n return word; // IF CH IS NOT IN WORD;\n reverse(word.begin(), word.begin() + (ind + 1)); // REVERSE FROM STARTING TO POSITION OF CH +1;\n ...
3
0
['Two Pointers', 'String', 'C++']
0
reverse-prefix-of-word
🍉0ms||✅Beats 100%🔥|| Beginner friendly || Explained🙌
0msbeats-100-beginner-friendly-explained-i2f3
Intuition\nNothing but we just traverse whole string until we find given ch in word\n\n# Approach\n1) Intialize index = 0; //for finding index\n2) So first we f
dharmikgohil
NORMAL
2024-05-01T04:19:01.434942+00:00
2024-05-01T04:19:01.434964+00:00
207
false
# Intuition\nNothing but we just traverse whole string until we find given ch in word\n\n# Approach\n1) Intialize index = 0; //for finding index\n2) So first we find the index of ch at which index it occuring in word\n3) If we find that index so we given it to index = i;\n4) Now let\'s create empty string and stores ch...
3
0
['String', 'Python', 'C++', 'Java']
0
reverse-prefix-of-word
Full Detailed Explanation 🔥✅
full-detailed-explanation-by-shivakumar1-knvo
Intuition\nSimple brute force, find the index of ch and just reverse from 0 to chth index.\n# Code Explanation\n\n\n - Two integer variables left and right are
shivakumar1
NORMAL
2024-05-01T03:09:29.498930+00:00
2024-05-01T03:09:29.498954+00:00
555
false
# Intuition\nSimple brute force, find the index of `ch` and just reverse from 0 to `ch`th index.\n# Code Explanation\n\n\n - Two integer variables `left` and `right` are initialized to 0 and the index of the first occurrence of character `ch` in the string `word`, respectively.\n - A `StringBuilder` named `sb` is ini...
3
0
['Two Pointers', 'String', 'Java']
1
reverse-prefix-of-word
Beginner friendly Easy JAVA solution🚀
beginner-friendly-easy-java-solution-by-anjih
Intuition\nThe approach involves finding the index of the first occurrence of the given character ch in the string word. If the index is greater than 0, reverse
parthiv_77
NORMAL
2024-02-04T06:01:40.543075+00:00
2024-02-04T06:01:40.543101+00:00
123
false
# Intuition\nThe approach involves finding the index of the first occurrence of the given character ch in the string word. If the index is greater than 0, reverse the substring from the beginning of the word up to that index, and concatenate it with the remaining portion of the word.\n\n# Approach\nFind the index of th...
3
0
['Java']
0
reverse-prefix-of-word
Simple Solution
simple-solution-by-adwxith-wgtg
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
adwxith
NORMAL
2023-11-15T15:03:36.875883+00:00
2023-11-15T15:03:36.875912+00:00
198
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)$$ --...
3
0
['JavaScript']
1
reverse-prefix-of-word
✅Just in 3 lines | 0ms | Easy Approach
just-in-3-lines-0ms-easy-approach-by-ash-ek4e
Intuition\nWe just need the index of the character \'ch\', then just reverse the order from beginning to the end. That\'s it!!\n\n# Approach\nI\'m getting the i
ashitoshsable07
NORMAL
2023-06-08T21:29:33.640698+00:00
2023-06-08T21:29:33.640728+00:00
253
false
# Intuition\nWe just need the **index** of the character \'ch\', then just reverse the order from beginning to the end. That\'s it!!\n\n# Approach\nI\'m getting the index of the character \'ch\' by using find function after that I\'m reversing the string from word.begin() to that index of ch.\n\n# Complexity\n- Time co...
3
0
['C++']
1
reverse-prefix-of-word
Java Easy Solution | 0 ms - 100% beats
java-easy-solution-0-ms-100-beats-by-ako-l0vd
Approach\n Describe your approach to solving the problem. \n1. Find the index of the first occurrence of the character \'ch\' in the given string \'word\' using
akobirswe
NORMAL
2023-05-30T13:53:34.094454+00:00
2023-05-30T13:53:34.094484+00:00
283
false
# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Find the index of the first occurrence of the character \'ch\' in the given string \'word\' using the `indexOf` method. If the character is not found (index is -1), return the original string \'word\' since there is nothing to reverse.\n2. Create a...
3
0
['Array', 'Two Pointers', 'String', 'Java']
1
reverse-prefix-of-word
C# easy
c-easy-by-ghmarek-bi0m
Code\n\npublic class Solution {\n public string ReversePrefix(string word, char ch) {\n\n char[] tempCharArr = word.ToArray();\n\n Array.Revers
GHMarek
NORMAL
2023-04-24T16:32:05.038599+00:00
2023-04-24T16:32:05.038632+00:00
39
false
# Code\n```\npublic class Solution {\n public string ReversePrefix(string word, char ch) {\n\n char[] tempCharArr = word.ToArray();\n\n Array.Reverse(tempCharArr, 0, word.IndexOf(ch) + 1);\n\n return new string(tempCharArr);\n \n }\n}\n```
3
0
['C#']
0
reverse-prefix-of-word
Go easy solution
go-easy-solution-by-azizjon003-glh1
\n# Complexity\n- Time complexity:59%\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:70%\n Add your space complexity here, e.g. O(n) \n\n# Co
Azizjon003
NORMAL
2023-04-12T08:48:16.737121+00:00
2023-04-12T08:48:16.737163+00:00
199
false
\n# Complexity\n- Time complexity:59%\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:70%\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nfunc reversePrefix(word string, ch byte) string {\n a := []byte(word)\n\n for i := 0; i < len(word); i++ {\n if word...
3
0
['Array', 'String', 'Go']
1
reverse-prefix-of-word
Easy Python3 Solution
easy-python3-solution-by-smisuol-s34b
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
smisuol
NORMAL
2023-02-05T04:55:53.023500+00:00
2023-02-05T04:56:23.629684+00:00
621
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. $...
3
0
['Python3']
2
reverse-prefix-of-word
Beats 99.38%
beats-9938-by-codequeror-xlcw
Upvote it :)\n\nclass Solution:\n def reversePrefix(self, word: str, ch: str) -> str:\n try:\n idx = word.index(ch)\n w = word[:
Codequeror
NORMAL
2023-01-21T14:14:08.418562+00:00
2023-01-21T14:14:08.418603+00:00
624
false
# Upvote it :)\n```\nclass Solution:\n def reversePrefix(self, word: str, ch: str) -> str:\n try:\n idx = word.index(ch)\n w = word[:idx + 1]\n return w[::-1] + word[idx + 1:]\n except: return word\n```
3
1
['Python', 'Python3']
0
reverse-prefix-of-word
JAVA || TWO POINTER APPROACH || BEATS 96%
java-two-pointer-approach-beats-96-by-sh-fdd0
\n\n# Code\n\nclass Solution {\n public String reversePrefix(String word, char ch) {\n char[] array = word.toCharArray();\n int i = 0;\n
sharforaz_rahman
NORMAL
2022-12-05T17:56:06.705542+00:00
2022-12-05T17:56:06.705578+00:00
808
false
\n\n# Code\n```\nclass Solution {\n public String reversePrefix(String word, char ch) {\n char[] array = word.toCharArray();\n int i = 0;\n int j = word.length();\n int index = 0;\n while (i < j) {\n if (array[i] == ch) {\n index = i;\n brea...
3
0
['Java']
1
reverse-prefix-of-word
Java Two pointers approach(1ms)
java-two-pointers-approach1ms-by-amrishr-3qg4
public String reversePrefix(String word, char ch) {\n int start=0;\n char[] temp=word.toCharArray();\n for(int end=0;end<temp.length;end++)
AmrishRaaj
NORMAL
2022-10-31T05:04:52.531531+00:00
2022-10-31T05:04:52.531571+00:00
653
false
public String reversePrefix(String word, char ch) {\n int start=0;\n char[] temp=word.toCharArray();\n for(int end=0;end<temp.length;end++)\n {\n if(temp[end]==ch)\n {\n while(start<end)\n {\n char tempS=temp[start];\n ...
3
0
['Java']
1
reverse-prefix-of-word
Javascript O(N) - One Iteration
javascript-on-one-iteration-by-videshgho-vb00
\n/**\n * @param {string} word\n * @param {character} ch\n * @return {string}\n */\nvar reversePrefix = function(word, ch) {\n const index = word.indexOf(ch
videshghodarop
NORMAL
2022-10-06T14:04:56.108354+00:00
2022-10-06T14:04:56.108394+00:00
358
false
```\n/**\n * @param {string} word\n * @param {character} ch\n * @return {string}\n */\nvar reversePrefix = function(word, ch) {\n const index = word.indexOf(ch);\n if (index === -1) return word;\n let result = \'\';\n\n for (let i = 0; i < word.length; i++) {\n if (i <= index) {\n result = word[i] + resu...
3
0
['JavaScript']
0
reverse-prefix-of-word
Python Easy Solution in 5 Lines
python-easy-solution-in-5-lines-by-pulki-whm1
\nclass Solution:\n def reversePrefix(self, word: str, ch: str) -> str:\n if ch not in word:\n return word\n i=word.index(ch)\n
pulkit_uppal
NORMAL
2022-10-02T13:56:22.422498+00:00
2022-10-02T13:56:22.422539+00:00
503
false
```\nclass Solution:\n def reversePrefix(self, word: str, ch: str) -> str:\n if ch not in word:\n return word\n i=word.index(ch)\n word=word[i::-1]+word[i+1:]\n return word\n```
3
0
['Python']
2
reverse-prefix-of-word
c++ easy
c-easy-by-sailakshmi1-4sm5
```\nclass Solution {\npublic:\n string reversePrefix(string word, char ch) {\n int j=0;\n int n=word.length();\n for(int i=0;i<n;i++){\
sailakshmi1
NORMAL
2022-06-15T14:15:02.983243+00:00
2022-06-15T14:15:43.256753+00:00
136
false
```\nclass Solution {\npublic:\n string reversePrefix(string word, char ch) {\n int j=0;\n int n=word.length();\n for(int i=0;i<n;i++){\n if(word[i]==ch){\n reverse(word.begin(),word.begin()+i+1);\n break;\n }\n }\n return word;\n }\...
3
0
['C']
0
reverse-prefix-of-word
java 76% easy to understand!
java-76-easy-to-understand-by-m_israilov-evvi
\n\nclass Solution {\n public String reversePrefix(String word, char ch) {\n Integer a = word.indexOf(ch + "");\n StringBuilder b = new
m_israilovv
NORMAL
2022-05-22T16:14:02.522223+00:00
2022-05-22T16:14:11.461870+00:00
88
false
```\n\n```class Solution {\n public String reversePrefix(String word, char ch) {\n Integer a = word.indexOf(ch + "");\n StringBuilder b = new StringBuilder(word.substring(0, a + 1));\n return b.reverse() + word.substring(a + 1, word.length());\n }\n}
3
0
[]
2
reverse-prefix-of-word
Smart & fastest java solution using substring and without any loop 3 line code. 0 ms
smart-fastest-java-solution-using-substr-t1xi
\nclass Solution {\n public String reversePrefix(String word, char ch) \n {\n StringBuilder s = new StringBuilder();\n int index = word.inde
saurabh_173
NORMAL
2022-02-23T15:28:54.070531+00:00
2022-02-23T15:28:54.070574+00:00
196
false
```\nclass Solution {\n public String reversePrefix(String word, char ch) \n {\n StringBuilder s = new StringBuilder();\n int index = word.indexOf(ch);\n s.append(word.substring(0,index+1));\n s.reverse();\n s.append(word.substring(index+1));\n return s.toString();\n }...
3
0
['String', 'Java']
0
reverse-prefix-of-word
[Python3/Golang] Easy to understand
python3golang-easy-to-understand-by-frol-ae78
First of all we want to check if there is a ch in the word, then we have to return ch index plus 1, reverse the order and add the remainder of the word unchange
frolovdmn
NORMAL
2021-09-15T08:43:59.331564+00:00
2025-01-19T14:37:37.689396+00:00
136
false
First of all we want to check if there is a **ch** in the **word**, then we have to return **ch** index plus 1, reverse the order and add the remainder of the **word** unchanged ```python [] class Solution: def reversePrefix(self, word: str, ch: str) -> str: return word[:word.index(ch) + 1][::-1] + word[wo...
3
0
['Python', 'Go', 'Python3']
0
reverse-prefix-of-word
C++ very easy solution
c-very-easy-solution-by-pk_87-oapj
```\nclass Solution {\npublic:\n string reversePrefix(string word, char ch) {\n \n int index=word.find(ch);\n if(index == -1)\n
pawan_mehta
NORMAL
2021-09-12T04:09:27.889522+00:00
2021-09-12T04:09:27.889549+00:00
128
false
```\nclass Solution {\npublic:\n string reversePrefix(string word, char ch) {\n \n int index=word.find(ch);\n if(index == -1)\n return word;\n reverse(word.begin(),word.begin()+index+1);\n return word;\n }\n};
3
0
[]
2
reverse-prefix-of-word
🔥🚀Two Easy Approach💯 || Time --O(n)
two-easy-approach-time-on-by-0xjwuvdyfc-h4eb
Reverse Prefix of a WordProblem StatementGiven a string word and a character ch, reverse the prefix of word that ends with ch. If ch does not exist in word, ret
0XjwUvdYfc
NORMAL
2025-03-24T07:52:28.629085+00:00
2025-03-24T07:52:28.629085+00:00
157
false
## Reverse Prefix of a Word ### Problem Statement Given a string `word` and a character `ch`, reverse the prefix of `word` that ends with `ch`. If `ch` does not exist in `word`, return `word` unchanged. ### Approach 1. Use a stack to store characters until we find `ch`. 2. If `ch` is found, reverse the stored charact...
2
0
['String', 'Stack', 'Java']
0
reverse-prefix-of-word
Beats 100% in runtime 🔥| Optimal O(1) solution ⏳| Very Easy Approach ✨
beats-100-in-runtime-optimal-o1-solution-fa79
IntuitionThe problem requires reversing a prefix of a given string up to the first occurrence of a specified character. The idea is to locate this character and
Dev_Sh
NORMAL
2025-03-14T00:00:59.409499+00:00
2025-03-14T00:00:59.409499+00:00
70
false
# Intuition The problem requires reversing a prefix of a given string up to the first occurrence of a specified character. The idea is to locate this character and reverse the portion of the string from the beginning to that index. # Approach 1. First, check if the character `ch` exists in the string using `word.find(...
2
0
['C++']
0
reverse-prefix-of-word
beats 100%,super simple python3 code
beats-100super-simple-python3-code-by-pr-5zgk
IntuitionApproachComplexity Time complexity: Space complexity: Code
PranaviGuddanti
NORMAL
2025-02-03T13:53:03.957506+00:00
2025-02-03T13:53:03.957506+00:00
157
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 `...
2
0
['Python3']
0
reverse-prefix-of-word
C++ 100% beating Brute Force
c-100-beating-brute-force-by-itsaditya7-bz3v
null
itsaditya7
NORMAL
2024-12-11T07:52:13.530642+00:00
2024-12-11T07:52:31.772900+00:00
45
false
# Intuition\nJust find the ch.and reverse the string till the ith index.\n\n# Approach\nStart the code with onw for loop to find the character position from where we want to reverse the string.\n\n# Complexity\n- Time complexity:\nO(MN)\nwhere \nM:number at which the ch is found\n\n- Space complexity:\nO(1)\n\n# Code\n...
2
0
['C++']
0
reverse-prefix-of-word
Effortless Character-Based Prefix Reversal in C++
effortless-character-based-prefix-revers-4r6q
Intuition\n\nWhen thinking about how to reverse a part of a string based on the presence of a specific character, the first thought is to determine the position
MahmoudMohamedElsayed
NORMAL
2024-10-10T19:04:10.813172+00:00
2024-10-10T19:04:10.813201+00:00
21
false
# Intuition\n\nWhen thinking about how to reverse a part of a string based on the presence of a specific character, the first thought is to determine the position of that character. Once the character is found, we can reverse the portion of the string that precedes it. This will allow us to achieve the desired result e...
2
0
['C++']
0
reverse-prefix-of-word
easy solution | 100.00% beats
easy-solution-10000-beats-by-q0art-3gfv
\n\ntypescript []\nconst reversePrefix = (string: string, char: string) => {\n const index = string.indexOf(char)\n\n return string.slice(0, index + 1).split(
q0art
NORMAL
2024-09-24T22:03:57.498754+00:00
2024-09-24T22:03:57.498785+00:00
45
false
![{E3946E6C-8EE4-4003-A0EA-2820A88899A3}.png](https://assets.leetcode.com/users/images/a9719720-c76f-4a5c-834a-1b054938e22e_1727215385.185507.png)\n\n```typescript []\nconst reversePrefix = (string: string, char: string) => {\n const index = string.indexOf(char)\n\n return string.slice(0, index + 1).split("").reverse...
2
0
['TypeScript']
0
reverse-prefix-of-word
Q. 2000 | ✅Beginner-Friendly Python Code | 4️⃣ lined.
q-2000-beginner-friendly-python-code-4-l-lttx
Intuition\nThe problem asks us to reverse the prefix of a string up to and including the first occurrence of a given character ch. The most efficient approach i
charan1kh
NORMAL
2024-08-08T16:29:17.798771+00:00
2024-09-21T08:01:37.318440+00:00
87
false
# Intuition\nThe problem asks us to reverse the prefix of a string up to and including the first occurrence of a given character ch. The most efficient approach is to locate ch once, reverse the portion of the string up to its index, and then concatenate it with the remaining part of the string.\n\n\n# Approach\n1. Fin...
2
0
['Python3']
2
reverse-prefix-of-word
Best and Easy to Understand ✅ || Beats 100% 🎯
best-and-easy-to-understand-beats-100-by-ynlk
Intuition\n Describe your first thoughts on how to solve this problem. The task requires reversing a part of the string from the start up to and including the f
rckrockerz
NORMAL
2024-05-23T09:37:10.623796+00:00
2024-05-23T09:37:10.623825+00:00
39
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->The task requires reversing a part of the string from the start up to and including the first occurrence of a given character. If the character does not exist in the string, the string remains unchanged. The idea is straightforward: find th...
2
0
['Two Pointers', 'String', 'C++']
0
reverse-prefix-of-word
JAVA SOLUTION
java-solution-by-deleted_user-q2xe
Code\n\nclass Solution {\n public String reversePrefix(String word, char ch) {\n # initialise strings\n String ans = "";\n String rev =
deleted_user
NORMAL
2024-05-03T16:04:08.987809+00:00
2024-05-03T16:04:08.987837+00:00
434
false
# Code\n```\nclass Solution {\n public String reversePrefix(String word, char ch) {\n # initialise strings\n String ans = "";\n String rev = "";\n # iterate through word and find the character\n int n = word.length();\n for(int i = 0; i < n; i++) {\n if(word.charA...
2
0
['Java']
0
reverse-prefix-of-word
Golang beats 100%
golang-beats-100-by-do2358-ju1d
Intuition\n Describe your first thoughts on how to solve this problem. \n- The reversePrefix function iterates through each character of the input word.\n- For
do2358
NORMAL
2024-05-02T15:20:03.901615+00:00
2024-05-02T15:20:03.901651+00:00
66
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- The reversePrefix function iterates through each character of the input word.\n- For each character at index i, it checks if it matches the target character ch.\n- If a match is found, the function proceeds to reverse the prefix.\n# App...
2
0
['Go']
0
reverse-prefix-of-word
Simple Solution [Faster than 82% Runtime]✅
simple-solution-faster-than-82-runtime-b-tu7j
Approach\n- Exit function block early, if word does not contain given ch\n- Get the index for ch in the word string\n- Split word into two subsequences, reverse
ProbablyLost
NORMAL
2024-05-02T12:54:40.377943+00:00
2024-05-02T12:57:35.951565+00:00
52
false
# Approach\n- Exit function block early, if `word` does not contain given `ch`\n- Get the `index` for ch in the word string\n- Split word into two subsequences, `reversedFirstPart` and `secondPart`\n- Concatenate and **return** the subsequences\n\n# Code\n```\nclass Solution {\n func reversePrefix(_ word: String, _ ...
2
0
['String', 'Swift']
0
reverse-prefix-of-word
C++ easiest solution Beats 100% solutions. 2 pointer method
c-easiest-solution-beats-100-solutions-2-tudj
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
_chitransh_9
NORMAL
2024-05-01T18:02:50.425590+00:00
2024-05-01T18:02:50.425617+00:00
193
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++']
2
monotone-increasing-digits
Simple and very short C++ solution
simple-and-very-short-c-solution-by-zee-3eoc
\nclass Solution {\npublic:\n int monotoneIncreasingDigits(int N) {\n string n_str = to_string(N);\n \n int marker = n_str.size();\n
zee
NORMAL
2017-12-03T04:22:26.099000+00:00
2018-08-16T19:01:56.570651+00:00
13,652
false
```\nclass Solution {\npublic:\n int monotoneIncreasingDigits(int N) {\n string n_str = to_string(N);\n \n int marker = n_str.size();\n for(int i = n_str.size()-1; i > 0; i --) {\n if(n_str[i] < n_str[i-1]) {\n marker = i;\n n_str[i-1] = n_str[i-1]...
156
5
[]
18
monotone-increasing-digits
Clean Code
clean-code-by-gracemeng-zzyw
The result should be:\n\npreceding monotone increasing digits (ending digit should decrease by 1) \n\nfollowed by \n\nall remaining digits set to \'9\'\n\n.\n\n
gracemeng
NORMAL
2018-07-17T07:00:20.750349+00:00
2020-08-21T15:33:16.652768+00:00
6,270
false
The result should be:\n```\npreceding monotone increasing digits (ending digit should decrease by 1) \n```\nfollowed by \n```\nall remaining digits set to \'9\'\n```\n.\n\n`e.g. N = 12321, the result is 12299`.\n```\nmonotoneIncreasingEnd is finalized as : 2\ncurrent arrN : 12211\narrN is finalized as : 12299\n```\n***...
96
1
[]
8
monotone-increasing-digits
Simple Python solution w/ Explanation
simple-python-solution-w-explanation-by-zadha
The idea is to go from the LSB to MSB and find the last digit, where an inversion happens.\nThere are 2 cases to consider:\n\ncase 1:\nIn 14267 , we see that in
Cubicon
NORMAL
2017-12-03T04:04:22.478000+00:00
2018-09-12T07:23:11.031465+00:00
7,588
false
The idea is to go from the LSB to MSB and find the last digit, where an inversion happens.\nThere are 2 cases to consider:\n\ncase 1:\nIn 14267 , we see that inversion happens at 4. In this case, then answer is obtained by reducing 4 to 3, and changing all the following digits to 9. \n=> 13999\n\ncase 2:\n1444267, here...
64
3
[]
13
monotone-increasing-digits
Simple java solution with clear explanation. Very easy to understand.
simple-java-solution-with-clear-explanat-foaw
\nclass Solution {\n public int monotoneIncreasingDigits(int N) {\n //1. Convert the given integer to character array\n char[] ch = String.valu
sushant_chaudhari
NORMAL
2018-05-04T00:05:28.074020+00:00
2018-05-04T00:05:28.074020+00:00
3,623
false
```\nclass Solution {\n public int monotoneIncreasingDigits(int N) {\n //1. Convert the given integer to character array\n char[] ch = String.valueOf(N).toCharArray();\n \n //2. Create a integer mark variable and initialize it to the length of the character array \n int mark = ch.l...
42
2
[]
4
monotone-increasing-digits
Python, Straightforward Greedy Solution Explained
python-straightforward-greedy-solution-e-9zgs
Let\'s look at a few examples:\n\nInput Output\n55627 -> 55599\n55427 -> 49999\n99996 -> 89999 \n100 -> 99\n\nFrom the
ruxinzzz
NORMAL
2022-02-12T01:34:18.333730+00:00
2022-02-18T20:37:25.571505+00:00
1,304
false
Let\'s look at a few examples:\n```\nInput Output\n55627 -> 55599\n55427 -> 49999\n99996 -> 89999 \n100 -> 99\n```\nFrom the above examples we can see that if a number is **not** monotone increasing digits, we will need to convert as many digits as posible to `9` and decrease t...
23
0
['Greedy', 'Python']
3
monotone-increasing-digits
cpp simple solution explanation with example beats 100% time and space
cpp-simple-solution-explanation-with-exa-3o0d
Runtime: 0 ms, faster than 100.00% of C++ online submissions for Monotone Increasing Digits.\nMemory Usage: 5.9 MB, less than 100.00% of C++ online submissions
_mrbing
NORMAL
2020-05-25T12:59:05.879052+00:00
2020-05-25T12:59:05.879091+00:00
1,554
false
Runtime: 0 ms, faster than 100.00% of C++ online submissions for Monotone Increasing Digits.\nMemory Usage: 5.9 MB, less than 100.00% of C++ online submissions for Monotone Increasing Digits.\nLogic : any number \'xxxxx..\' a number monotonically increasing largest but smaller than original number will be one less tha...
22
0
['C++']
2
monotone-increasing-digits
C++ | BFS approach
c-bfs-approach-by-wh0ami-fg48
\nclass Solution {\npublic:\n int monotoneIncreasingDigits(int N) {\n \n queue<long>q;\n for (int i = 1; i <= 9; i++)\n q.pus
wh0ami
NORMAL
2020-06-18T05:34:06.752796+00:00
2020-06-18T05:34:06.752849+00:00
918
false
```\nclass Solution {\npublic:\n int monotoneIncreasingDigits(int N) {\n \n queue<long>q;\n for (int i = 1; i <= 9; i++)\n q.push(i);\n \n int res = INT_MIN;\n while (!q.empty()) {\n int t = q.front();\n q.pop();\n \n if...
20
0
[]
3
monotone-increasing-digits
Simple and very short Java solution
simple-and-very-short-java-solution-by-b-f083
//translated from the simple and very short c++ solution\n\n\n public int monotoneIncreasingDigits(int N) {\n\n if(N<=9)\n return N;\n
brucezu
NORMAL
2017-12-03T09:00:47.355000+00:00
2017-12-03T09:00:47.355000+00:00
4,504
false
//translated from the simple and very short c++ solution\n\n```\n public int monotoneIncreasingDigits(int N) {\n\n if(N<=9)\n return N;\n char[] x = String.valueOf(N).toCharArray();\n\n int mark = x.length;\n for(int i = x.length-1;i>0;i--){\n if(x[i]<x[i-1]){\n ...
17
1
[]
1
monotone-increasing-digits
Python3 || 7 lines w/explanation || T/S: 82% / 87%
python3-7-lines-wexplanation-ts-82-87-by-pkys
\nclass Solution:\n def monotoneIncreasingDigits(self, n: int) -> int:\n\n n = str(n) # For example: n = 246621
Spaulding_
NORMAL
2022-09-20T17:22:20.540912+00:00
2024-05-29T19:16:36.568363+00:00
786
false
```\nclass Solution:\n def monotoneIncreasingDigits(self, n: int) -> int:\n\n n = str(n) # For example: n = 246621 --> "246621"\n N = len(n)\n\n for i in range(N-1): # find the first break in monotonicity\n if n[i] > ...
16
1
['Python', 'Python3']
1
monotone-increasing-digits
Simple Java, from back to front, no extra space and no conversion to char[]
simple-java-from-back-to-front-no-extra-fl047
\nclass Solution {\n public int monotoneIncreasingDigits(int N) {\n int res = 0;\n int pre = Integer.MAX_VALUE;\n int offset = 1;\n
shibai86
NORMAL
2018-07-03T06:12:30.639364+00:00
2018-10-10T19:12:50.924558+00:00
1,052
false
```\nclass Solution {\n public int monotoneIncreasingDigits(int N) {\n int res = 0;\n int pre = Integer.MAX_VALUE;\n int offset = 1;\n while(N != 0) {\n int digit = N % 10;\n if(digit > pre) {\n res = digit * offset - 1;\n pre = digit - ...
14
1
[]
3
monotone-increasing-digits
[Java/C++] 0ms || Awesome approach || 100% faster
javac-0ms-awesome-approach-100-faster-by-yak8
Attention \u2757\nAvoid the following approach, it is too expensive because of n-- statements\u2757. \n\npublic int monotoneIncreasingDigits(int n) {\n w
im_obid
NORMAL
2023-01-15T21:35:53.354207+00:00
2023-01-15T23:40:44.004404+00:00
1,731
false
# Attention \u2757\nAvoid the following approach, it is too expensive because of ```n--``` statements\u2757. \n```\npublic int monotoneIncreasingDigits(int n) {\n while (!isSatisfies(n)) {\n n--;\n }\n return n;\n }\n\n public boolean isSatisfies(int n) {\n int k = 10;\n ...
12
0
['C++', 'Java']
4
monotone-increasing-digits
Fast and simple 40ms Python solution using recursion
fast-and-simple-40ms-python-solution-usi-bxj8
We scan through S from left to right:\n If it\'s monotonically increasing we just adding corresponding part to result\n If not then we simply decrease result by
rouroukerr
NORMAL
2018-10-16T01:18:35.834038+00:00
2018-10-24T14:55:12.274831+00:00
802
false
We scan through S from left to right:\n* If it\'s monotonically increasing we just adding corresponding part to result\n* If not then we simply decrease result by 1, which would result in some 9s in the tail\n* However, decrease by 1 might lead to our result being not monotonically increasing, so we run recursion base ...
10
0
[]
3
monotone-increasing-digits
easy java
easy-java-by-0xdeadbeef-vszc
\n public int monotoneIncreasingDigits(int N) {\n char[] digit = (N + "").toCharArray();\n int flag = digit.length;\n for (int i = digit
0xdeadbeef_
NORMAL
2017-12-14T14:54:30.249000+00:00
2017-12-14T14:54:30.249000+00:00
1,281
false
```\n public int monotoneIncreasingDigits(int N) {\n char[] digit = (N + "").toCharArray();\n int flag = digit.length;\n for (int i = digit.length - 1; i > 0; i--) {\n if (digit[i] < digit[i - 1]) {\n digit[i - 1]--;\n flag = i;\n }\n }\...
8
0
[]
0
monotone-increasing-digits
738: Solution with step by step explanation
738-solution-with-step-by-step-explanati-so3v
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n\ndigits = list(str(n))\n\nWe first convert the integer n to its string r
Marlen09
NORMAL
2023-10-20T18:48:59.005595+00:00
2023-10-20T18:48:59.005621+00:00
540
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n```\ndigits = list(str(n))\n```\nWe first convert the integer n to its string representation and then create a list of its characters.\nThis step allows us to easily modify individual digits if needed.\n\n```\nn = len(digits...
7
0
['Math', 'Greedy', 'Python', 'Python3']
0
monotone-increasing-digits
[C++] Simplest Greedy Solution Faster than 100%
c-simplest-greedy-solution-faster-than-1-u9hn
We need to return the largest number that is less than or equal to the given n, that has monotome increasing digits.\n\nAPPROACH :\n\n If the number n is monoto
Mythri_Kaulwar
NORMAL
2022-02-18T04:06:12.029495+00:00
2022-02-18T04:06:53.233991+00:00
966
false
We need to return the largest number that is less than or equal to the given ```n```, that has monotome increasing digits.\n\n**APPROACH :**\n\n* If the number ```n``` is monotone increasing then, we can return the number itself.\n* Otherwise, we start traversing from the last digit.\n* Wherever we find a digit that\'...
6
0
['Greedy', 'C', 'C++']
1
monotone-increasing-digits
Solution in c++
solution-in-c-by-ashish_madhup-dwxk
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
ashish_madhup
NORMAL
2023-02-26T16:29:37.900514+00:00
2023-02-26T16:29:37.900618+00:00
673
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)$$ --...
5
0
['C++']
0
monotone-increasing-digits
java simple
java-simple-by-jstm2022-lkrt
\nclass Solution {\n public int monotoneIncreasingDigits(int n) {\n char[] arr = String.valueOf(n).toCharArray();\n int start = arr.length;\n
JSTM2022
NORMAL
2022-04-26T02:00:47.759331+00:00
2022-04-26T02:00:47.759378+00:00
673
false
```\nclass Solution {\n public int monotoneIncreasingDigits(int n) {\n char[] arr = String.valueOf(n).toCharArray();\n int start = arr.length;\n for (int i = arr.length - 2; i >= 0; i --) {\n if (arr[i] > arr[i + 1]) {\n start = i + 1;\n arr[i] --;\n ...
5
0
['Java']
0
monotone-increasing-digits
very intuitional Java solution using stack
very-intuitional-java-solution-using-sta-xo56
```\n public int monotoneIncreasingDigits(int N) {\n char[] num = String.valueOf(N).toCharArray();\n Stack stack = new Stack<>();\n boolea
peachfan
NORMAL
2019-09-28T15:11:22.087463+00:00
2019-09-28T15:11:22.087504+00:00
273
false
```\n public int monotoneIncreasingDigits(int N) {\n char[] num = String.valueOf(N).toCharArray();\n Stack<Character> stack = new Stack<>();\n boolean find = false;\n for (int i = 0; i < num.length; i++) {\n char ch = num[i];\n while (!stack.isEmpty() && stack.peek() >...
5
0
[]
0
monotone-increasing-digits
[Java] ✅ O(1) ✅ 1MS ✅ 100% ✅ FAST ✅ BEST ✅ CLEAN CODE
java-o1-1ms-100-fast-best-clean-code-by-d380f
Approach\n1. Looking at the numbers, the highest monotone increasing increasing is ending with 9 (unless number is already monotone: eg: 12345)\n2. To obtain nu
StefanelStan
NORMAL
2024-10-14T08:47:49.801271+00:00
2024-10-14T08:47:49.801306+00:00
219
false
# Approach\n1. Looking at the numbers, the highest monotone increasing increasing is ending with 9 (unless number is already monotone: eg: 12345)\n2. To obtain numbers ending with 9, subtract n % (j) + 1 from n, where j is a power of 10: 10,100, 1000.\n3. EG: \n - 332 - (332 % 10 + 1) = 332 - (2 + 1) = 332 - 3 = 329...
4
0
['Java']
1
monotone-increasing-digits
O(n) Python solution - very simple logic
on-python-solution-very-simple-logic-by-axagf
Example: n = 4329762\nfor loop: i = 6 -> if condition: 2 < 6 is true: n_str = 4329762 - 63 = 4329699\nfor loop: i = 5 -> if condition: 9 < 6 is false\nfor loop
getsatnow
NORMAL
2021-10-02T20:37:03.098544+00:00
2021-10-02T20:46:05.513469+00:00
287
false
Example: n = 4329762\nfor loop: i = 6 -> if condition: 2 < 6 is true: n_str = 4329762 - 63 = 4329699\nfor loop: i = 5 -> if condition: 9 < 6 is false\nfor loop i = 4 -> if condition: 6 < 9 is true: n_str = 4329699 - 9700 = 4319999\nand so on...\n```\nclass Solution:\n def monotoneIncreasingDigits(self, n: int) -> in...
4
0
[]
2
monotone-increasing-digits
Simple O(log n) Java solution with one pass
simple-olog-n-java-solution-with-one-pas-4nf5
We scan from right to left, i.e., least significant to most significan, take 7634 fro example: \n1. if the digits are strictly increasing from left to right, we
linvava
NORMAL
2020-06-16T04:56:46.888120+00:00
2020-06-16T04:58:07.530833+00:00
373
false
We scan from right to left, i.e., least significant to most significan, take 7634 fro example: \n1. if the digits are strictly increasing from left to right, we do nothing, so 34 -> 34.\n2. if a one digit is smaller than any digit on the right, the result would be the digit minus 1, and fill remaining digits with 9. 63...
4
0
[]
0
monotone-increasing-digits
Simple Python Solution
simple-python-solution-by-bigshen-romf
class Solution(object):\n def monotoneIncreasingDigits(self, N):\n """\n :type N: int\n :rtype: int\n """\n \n if N
bigshen
NORMAL
2017-12-25T03:42:30.241000+00:00
2018-10-24T15:14:16.938836+00:00
795
false
class Solution(object):\n def monotoneIncreasingDigits(self, N):\n """\n :type N: int\n :rtype: int\n """\n \n if N == 10:\n return 9\n if N < 20:\n return N\n num = [s for s in str(N)]\n i = len(num) - 1\n index = len(num) \...
4
1
[]
0
monotone-increasing-digits
Easy Java Solution || Beats 95%
easy-java-solution-beats-95-by-ravikumar-2qc8
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
ravikumar50
NORMAL
2023-09-07T14:36:09.951772+00:00
2023-09-07T14:36:09.951794+00:00
227
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)$$ --...
3
0
['Java']
1
monotone-increasing-digits
very easy to understand ! converting to string and solving in c++
very-easy-to-understand-converting-to-st-65ij
Approach\n1.First convert the number into a string using to_string( ).\n2.Then check each digit in a for loop if the prev digit is smaller than or equal to the
Trivial_03
NORMAL
2023-03-21T19:39:41.690681+00:00
2023-03-21T19:39:41.690713+00:00
593
false
# Approach\n1.First convert the number into a string using to_string( ).\n2.Then check each digit in a for loop if the prev digit is smaller than or equal to the next digit or not. If yes,then continue.\n3.If no then just make the rest leftout digits(to the right of index where condition is violated) to \'9\' and decre...
3
0
['C++']
0
monotone-increasing-digits
8 Line JS code
8-line-js-code-by-yutingkung-tebm
\nvar monotoneIncreasingDigits = function(n) {\n let arr = String(n).split(\'\');\n for (let i=arr.length-2; i>=0; i--) {\n if (arr[i]>arr[i+1]) {\
yutingkung
NORMAL
2022-01-07T03:52:23.385616+00:00
2022-01-07T03:52:23.385660+00:00
151
false
```\nvar monotoneIncreasingDigits = function(n) {\n let arr = String(n).split(\'\');\n for (let i=arr.length-2; i>=0; i--) {\n if (arr[i]>arr[i+1]) {\n arr[i]--;\n for(let j=i+1; j<arr.length; j++) arr[j]=\'9\';\n }\n }\n return Number(arr.join(\'\'));\n};\n```
3
0
['JavaScript']
0
monotone-increasing-digits
92 % ,Intuitive,Easy to Understand,GREEDY , Java
92-intuitiveeasy-to-understandgreedy-jav-9045
```\nclass Solution {\n public int monotoneIncreasingDigits(int n) {\n char [] arr=String.valueOf(n).toCharArray();\n for(int i=arr.length-2;i>
rtvksingh
NORMAL
2021-05-29T17:32:35.382147+00:00
2021-05-29T17:34:48.244907+00:00
141
false
```\nclass Solution {\n public int monotoneIncreasingDigits(int n) {\n char [] arr=String.valueOf(n).toCharArray();\n for(int i=arr.length-2;i>=0;i--){\n if(arr[i]<=arr[i+1])\n continue;\n else{\n arr[i]--;\n for(int j=i+1;j<arr.length;...
3
1
[]
0
monotone-increasing-digits
Easy O(N) JavaScript with explanation
easy-on-javascript-with-explanation-by-f-log5
\n\nconst monotoneIncreasingDigits = N => {\n \n // create any array of integers from number N\n const n = Array.from(\'\'+N, Number);\n \n let i = 0;\n \
fl4sk
NORMAL
2021-01-10T03:02:20.999461+00:00
2021-01-10T03:02:20.999498+00:00
276
false
```\n\nconst monotoneIncreasingDigits = N => {\n \n // create any array of integers from number N\n const n = Array.from(\'\'+N, Number);\n \n let i = 0;\n \n // find the cliff\n while(i < n.length-1 && n[i] <= n[i+1])\n i++;\n\n // decremnet the cliff and any values before the cliff which satisfy this condi...
3
0
['JavaScript']
0
monotone-increasing-digits
StraightForward Greedy Python Solution
straightforward-greedy-python-solution-b-xpeh
\n def monotoneIncreasingDigits(self, N):\n """\n :type N: int\n :rtype: int\n """\n s = str(N)\n if len(s) < 2:\n
yuchenliu0513
NORMAL
2020-12-03T08:15:02.377923+00:00
2020-12-03T08:15:02.377965+00:00
562
false
```\n def monotoneIncreasingDigits(self, N):\n """\n :type N: int\n :rtype: int\n """\n s = str(N)\n if len(s) < 2:\n return N\n ans = ""\n pre = 0\n for i in range(len(s)):\n if int(s[i]) >= pre:\n ans += s[i]\n ...
3
0
['Greedy', 'Python', 'Python3']
0
monotone-increasing-digits
c++,stack
cstack-by-sharma_amit-87ax
\nclass Solution {\n vector<int> convert_to_arr(int n){\n vector<int> v;\n while(n){\n int t = n%10;\n n = n/10;\n
sharma_amit
NORMAL
2020-09-29T16:18:41.544555+00:00
2020-09-29T16:19:51.815516+00:00
381
false
```\nclass Solution {\n vector<int> convert_to_arr(int n){\n vector<int> v;\n while(n){\n int t = n%10;\n n = n/10;\n v.push_back(t);\n }\n reverse(v.begin(),v.end());\n return v;\n }\n \n int convert_int(vector<int> nums){\n int ans...
3
0
['Stack', 'C']
0
monotone-increasing-digits
java 1ms solution with detailed explanation
java-1ms-solution-with-detailed-explanat-nwq4
This problem can be solved in greedy strategy:\n1. At first, we use a list to represent the given number N where list.get(0) is the highest number.\n2. Then, we
pangeneral
NORMAL
2019-05-09T00:38:42.625310+00:00
2019-05-09T00:38:42.625340+00:00
653
false
This problem can be solved in greedy strategy:\n1. At first, we use a list to represent the given number ```N``` where list.get(0) is the highest number.\n2. Then, we traverse from 0 to list.size() - 1 to find the **first** i that list[i] > list[i + 1]\n3. If we don\'t find such i, then return the given number. Otherwi...
3
0
['Math', 'Greedy', 'Java']
0
monotone-increasing-digits
Optimized Approach || 100% T.C || CPP
optimized-approach-100-tc-cpp-by-ganesh_-f7qu
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
Ganesh_ag10
NORMAL
2024-04-11T05:35:24.233137+00:00
2024-04-11T05:35:24.233173+00:00
555
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. $$O...
2
1
['C++']
0
monotone-increasing-digits
Easy C++ solution || Math Based
easy-c-solution-math-based-by-bharathgow-d43x
\n# Code\n\nclass Solution {\npublic:\n bool isMonotonic(int n){\n int k = 10;\n while(n > 0){\n if(k < n%10){\n retu
bharathgowda29
NORMAL
2023-12-27T15:43:01.273264+00:00
2023-12-27T15:43:01.273291+00:00
542
false
\n# Code\n```\nclass Solution {\npublic:\n bool isMonotonic(int n){\n int k = 10;\n while(n > 0){\n if(k < n%10){\n return false;\n }\n else{\n k = n%10;\n n = n/10;\n }\n }\n\n return true;\n }\n\...
2
0
['Math', 'Greedy', 'C++']
0
monotone-increasing-digits
Solution
solution-by-deleted_user-tga5
C++ []\nclass Solution {\npublic:\n int monotoneIncreasingDigits(int n) {\n string s = to_string(n);\n while(1){\n bool flag = false
deleted_user
NORMAL
2023-04-23T04:00:49.023701+00:00
2023-04-23T04:49:07.534319+00:00
873
false
```C++ []\nclass Solution {\npublic:\n int monotoneIncreasingDigits(int n) {\n string s = to_string(n);\n while(1){\n bool flag = false;\n for(int i = 1; i < s.length(); i++){\n if(s[i] >= s[i-1]) continue;\n else{\n s[i-1]--;\n ...
2
0
['C++', 'Java', 'Python3']
0
monotone-increasing-digits
Simple C++ Sloution
simple-c-sloution-by-sunnyyad2002-fwzx
Intuition\n Describe your first thoughts on how to solve this problem. \nSuppose we have a non-negative integer N, we have to find the largest number that is le
sunnyyad2002
NORMAL
2023-03-17T15:00:05.898375+00:00
2023-03-17T15:00:05.898399+00:00
905
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSuppose we have a non-negative integer N, we have to find the largest number that is less than or equal to N with monotone increasing digits. We know that an integer has monotone increasing digits if and only if each pair of adjacent digi...
2
0
['C++']
0
monotone-increasing-digits
Java faster than 100%
java-faster-than-100-by-ritik652018-jvnu
```\nclass Solution {\n \n public int monotoneIncreasingDigits(int n) {\n \n for(int i=n;i>=0;i--){\n int k=i;\n int x=k%10;
ritik652018
NORMAL
2022-09-24T08:10:16.458388+00:00
2023-10-20T06:48:49.243064+00:00
424
false
```\nclass Solution {\n \n public int monotoneIncreasingDigits(int n) {\n \n for(int i=n;i>=0;i--){\n int k=i;\n int x=k%10;\n int flag=0;\n int count=1;\n \n while(k>1){\n k=k/10;\n int y= k%10;\n ...
2
1
['Math', 'Java']
1
monotone-increasing-digits
Java Simple Solution without DP
java-simple-solution-without-dp-by-adity-uv1o
\nclass Solution {\n public int monotoneIncreasingDigits(int n) {\n int len = size(n);\n int[] dig = new int[len];\n len--;\n whi
Aditya001
NORMAL
2022-08-17T14:28:29.038537+00:00
2022-08-17T14:28:29.038605+00:00
995
false
```\nclass Solution {\n public int monotoneIncreasingDigits(int n) {\n int len = size(n);\n int[] dig = new int[len];\n len--;\n while(n>0){\n dig[len] = n%10;\n n /= 10;\n len--;\n }\n n = dig.length;\n int t = 10;\n\n while(t>...
2
0
['Java']
0
monotone-increasing-digits
Easiest C++ solution
easiest-c-solution-by-kazuma0803-5h2r
\nclass Solution {\npublic:\n int monotoneIncreasingDigits(int n) {\\\n string s=to_string(n);\n int x=s.size();\n for (int i=s.size()-1
Kazuma0803
NORMAL
2022-06-18T10:11:53.931180+00:00
2022-06-18T10:11:53.931210+00:00
336
false
```\nclass Solution {\npublic:\n int monotoneIncreasingDigits(int n) {\\\n string s=to_string(n);\n int x=s.size();\n for (int i=s.size()-1;i>0;i--) {\n if (s[i]<s[i-1]) {\n x=i;\n s[i-1]=s[i-1]-1;\n }\n }\n for (int i=x;i<s.size(...
2
0
['C']
0
monotone-increasing-digits
C++ 100% Faster
c-100-faster-by-kunal_patil-1koh
,,,\n\n int monotoneIncreasingDigits(int n) {\n \n vector v;\n \n while(n)\n {\n v.push_back(n%10);\n n
kunal_patil
NORMAL
2022-02-09T06:50:08.896254+00:00
2022-02-09T06:50:08.896284+00:00
219
false
,,,\n\n int monotoneIncreasingDigits(int n) {\n \n vector<int> v;\n \n while(n)\n {\n v.push_back(n%10);\n n=n/10;\n }\n \n for(int i=0;i<v.size();i++)\n {\n if(i<v.size()-1 && v[i]<v[i+1])\n {\n v[...
2
0
['Math', 'C']
0
monotone-increasing-digits
Simple C++ || Without changing into string || Stack Solution
simple-c-without-changing-into-string-st-4l5s
\nclass Solution {\npublic:\n int monotoneIncreasingDigits(int n) {\n int ans = 0;\n stack<int> st;\n \n while(n)\n {\n
goyalnaman198
NORMAL
2022-01-01T14:48:56.742441+00:00
2022-01-01T14:51:42.034462+00:00
236
false
```\nclass Solution {\npublic:\n int monotoneIncreasingDigits(int n) {\n int ans = 0;\n stack<int> st;\n \n while(n)\n {\n int last = n % 10; n /= 10;\n \n if(st.empty() or st.top() >= last)\n {\n st.push(last);\n ...
2
0
['Stack', 'C']
0