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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
roman-to-integer | ✅Beginner Friendly 🔥|| Step By Steps Solution ✅ || Beats 100% User in Each Solution of Me ✅🔥 || | beginner-friendly-step-by-steps-solution-sz15 | \n\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE AT THE END \u2705 :\n\n### Intuition :\nThe main idea behind converting a Roman numeral to an integer is to l | Letssoumen | NORMAL | 2024-11-10T01:44:27.779710+00:00 | 2024-11-10T01:44:27.779748+00:00 | 7,175 | false | \n\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE AT THE END \u2705 :\n\n### Intuition :\nThe main idea behind converting a Roman numeral to an integer is to look for specific patterns of subtraction. For instance, when a smaller numeral appears before a larger one (like IV for 4 or IX for 9), it implies a subtraction... | 30 | 1 | ['Hash Table', 'Math', 'C++', 'Java', 'Python3'] | 2 |
roman-to-integer | 💯✅HashMap Solution | JAVA | VERY EASY | hashmap-solution-java-very-easy-by-dipes-jdks | 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 | dipesh_12 | NORMAL | 2023-03-16T03:59:18.635899+00:00 | 2023-03-16T03:59:18.635931+00:00 | 8,228 | 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)$$ --... | 30 | 0 | ['Java'] | 3 |
roman-to-integer | Java solution Using HaspMap Faster than 100% (Easy to Understand) | java-solution-using-haspmap-faster-than-askjh | class Solution {\n public int romanToInt(String s) {\n Mapmap=new HashMap<>();\n map.put(\'I\', 1);\n map.put(\'V\', 5);\n map.pu | Abhishek_Mandge | NORMAL | 2022-08-08T07:54:08.766581+00:00 | 2022-08-08T07:54:08.766609+00:00 | 1,534 | false | class Solution {\n public int romanToInt(String s) {\n Map<Character,Integer>map=new HashMap<>();\n map.put(\'I\', 1);\n map.put(\'V\', 5);\n map.put(\'X\', 10);\n map.put(\'L\', 50);\n map.put(\'C\', 100);\n map.put(\'D\', 500);\n map.put(\'M\', 1000);\n ... | 30 | 0 | [] | 0 |
roman-to-integer | Python Solution with explanantion | python-solution-with-explanantion-by-amc-32ti | The idea is to walk each letter of the roman integer in sequence and undo previous addition in the case the previous roman numeral is less than the current one. | amchoukir | NORMAL | 2019-08-13T12:12:18.882484+00:00 | 2019-08-13T12:14:03.669516+00:00 | 4,655 | false | The idea is to walk each letter of the roman integer in sequence and undo previous addition in the case the previous roman numeral is less than the current one.\n\n```python\nclass Solution:\n def romanToInt(self, s: str) -> int:\n roman_to_int = {\n \'I\' : 1,\n \'V\' : 5,\n ... | 30 | 0 | ['Python', 'Python3'] | 3 |
roman-to-integer | [Java] Without Map | 3ms | java-without-map-3ms-by-ieshagupta-g7r9 | We don\'t need to use Extra memory. This problem can be solved easily without using any Map.\nHelper method:\n\n int getValue(char c){\n if(c==\'I\') ret | ieshagupta | NORMAL | 2021-06-19T18:56:21.708060+00:00 | 2021-06-19T18:56:21.708089+00:00 | 2,529 | false | We don\'t need to use Extra memory. This problem can be solved easily without using any Map.\nHelper method:\n```\n int getValue(char c){\n if(c==\'I\') return 1;\n else if(c==\'V\') return 5;\n else if(c==\'X\') return 10;\n else if(c==\'L\') return 50;\n else if(c==\'C\') return 100... | 29 | 0 | ['Java'] | 4 |
roman-to-integer | 🗓️ Daily LeetCoding Challenge August, Day 15 | daily-leetcoding-challenge-august-day-15-pxzf | This problem is the Daily LeetCoding Challenge for August, Day 15. Feel free to share anything related to this problem here! You can ask questions, discuss what | leetcode | OFFICIAL | 2022-08-15T00:00:07.679480+00:00 | 2022-08-15T00:00:07.679525+00:00 | 24,015 | false | This problem is the Daily LeetCoding Challenge for August, Day 15.
Feel free to share anything related to this problem here!
You can ask questions, discuss what you've learned from this problem, or show off how many days of streak you've made!
---
If you'd like to share a detailed solution to the problem, please cr... | 28 | 0 | [] | 64 |
roman-to-integer | C Solution Using a Switch Statement | c-solution-using-a-switch-statement-by-i-68ar | \nint getValue(const char * s){\n switch(*s) {\n case \'I\': return (s[1] == \'V\' || s[1] == \'X\') ? -1 : 1;\n case \'X\': return (s[1] == \' | irenemp | NORMAL | 2021-03-03T19:13:14.473827+00:00 | 2021-03-03T19:52:34.686144+00:00 | 2,136 | false | ```\nint getValue(const char * s){\n switch(*s) {\n case \'I\': return (s[1] == \'V\' || s[1] == \'X\') ? -1 : 1;\n case \'X\': return (s[1] == \'L\' || s[1] == \'C\') ? -10 : 10;\n case \'C\': return (s[1] == \'D\' || s[1] == \'M\') ? -100 : 100;\n case \'V\': return 5;\n case \'L... | 28 | 0 | ['C'] | 0 |
roman-to-integer | Python solution | python-solution-by-santhosh2-kzka | def romanToInt(self, s):\n\n romans = {'M': 1000, 'D': 500 , 'C': 100, 'L': 50, 'X': 10,'V': 5,'I': 1}\n\n prev_value = running_total | santhosh2 | NORMAL | 2015-01-15T16:26:39+00:00 | 2018-09-11T04:15:39.404201+00:00 | 7,903 | false | def romanToInt(self, s):\n\n romans = {'M': 1000, 'D': 500 , 'C': 100, 'L': 50, 'X': 10,'V': 5,'I': 1}\n\n prev_value = running_total =0\n \n for i in range(len(s)-1, -1, -1):\n int_val = romans[s[i]]\n if int_val < prev_value:\n ... | 28 | 1 | [] | 8 |
roman-to-integer | [Java] [Descriptive][Easy] 99% more efficient | java-descriptiveeasy-99-more-efficient-b-5ncv | Intuition\nFirstly I tried to implement "CORE LOGIC" of this problem then tried to enhance the solution with different approach. So I\'m sharing two solutions.\ | sadriddin17 | NORMAL | 2023-05-22T05:05:59.568083+00:00 | 2023-05-25T12:48:38.924543+00:00 | 11,024 | false | # Intuition\nFirstly I tried to implement "CORE LOGIC" of this problem then tried to enhance the solution with different approach. So I\'m sharing two solutions.\n\n# Approaches\n1. The solution iterates through the Roman numeral string from `right to left` and applies the necessary additions and subtractions based on ... | 27 | 0 | ['Hash Table', 'Math', 'String', 'Java'] | 3 |
roman-to-integer | Simple and Clean Solution - typeScript | javaScript | simple-and-clean-solution-typescript-jav-bv7x | \nfunction romanToInt(s: string): number {\nconst map = {\n \'I\':1,\n \'V\':5,\n \'X\':10,\n \'L\':50,\n \'C\':100,\n \'D\':500,\n \'M\':1 | saad189 | NORMAL | 2022-07-27T19:59:41.147543+00:00 | 2022-07-27T19:59:41.147590+00:00 | 3,646 | false | ```\nfunction romanToInt(s: string): number {\nconst map = {\n \'I\':1,\n \'V\':5,\n \'X\':10,\n \'L\':50,\n \'C\':100,\n \'D\':500,\n \'M\':1000,\n \'IV\':4,\n \'IX\':9,\n \'XL\':40,\n \'XC\':90,\n \'CD\':400,\n \'CM\':900\n}\n\n let sum = 0;\n for (let i = 0; i< s.length;)... | 27 | 0 | ['TypeScript', 'JavaScript'] | 4 |
roman-to-integer | 👾C#, Java, Python3,JavaScript Solution (Easy-Understanding) | c-java-python3javascript-solution-easy-u-zhg9 | C#,Java,Python3,JavaScript different solution with explanation\n\u2B50https://zyrastory.com/en/coding-en/leetcode-en/leetcode-13-roman-to-integer-solution-and-e | Daisy001 | NORMAL | 2022-10-20T23:33:07.178065+00:00 | 2022-10-20T23:33:07.178127+00:00 | 19,400 | false | ### C#,Java,Python3,JavaScript different solution with explanation\n**\u2B50[https://zyrastory.com/en/coding-en/leetcode-en/leetcode-13-roman-to-integer-solution-and-explanation-en/](https://zyrastory.com/en/coding-en/leetcode-en/leetcode-13-roman-to-integer-solution-and-explanation-en/)\u2B50**\n\n**\uD83E\uDDE1See ne... | 26 | 0 | ['Java', 'Python3', 'JavaScript'] | 3 |
roman-to-integer | [Rust] Simple and Fast | rust-simple-and-fast-by-mgrazianoc-51g5 | Intuition\nWe replace all edge cases to a sequence of characters.\n\n# Approach\nTo avoid if else statements on current and next elements of an interable of cha | mgrazianoc | NORMAL | 2023-03-27T19:23:02.964947+00:00 | 2023-03-27T19:23:56.366380+00:00 | 1,515 | false | # Intuition\nWe replace all edge cases to a sequence of characters.\n\n# Approach\nTo avoid `if else` statements on current and next elements of an interable of characters, we map each character to a `i32` on the fly!\n\n# Code\n```\nimpl Solution {\n pub fn roman_to_int(s: String) -> i32 {\n let s_translated... | 25 | 0 | ['Rust'] | 6 |
roman-to-integer | Easy Solution || HashMap || 10ms || JAVA | easy-solution-hashmap-10ms-java-by-rajbi-4ij4 | \nclass Solution {\n public int romanToInt(String s) {\n HashMap<Character, Integer> map = new HashMap<>();\n map.put(\'I\',1);\n map.pu | rajbirsingh1233 | NORMAL | 2022-03-21T07:43:56.250248+00:00 | 2022-03-23T12:23:17.781442+00:00 | 1,860 | false | ```\nclass Solution {\n public int romanToInt(String s) {\n HashMap<Character, Integer> map = new HashMap<>();\n map.put(\'I\',1);\n map.put(\'V\',5);\n map.put(\'X\',10);\n map.put(\'L\',50);\n map.put(\'C\',100);\n map.put(\'D\',500);\n map.put(\'M\',1000);\n... | 25 | 0 | ['Java'] | 1 |
roman-to-integer | My Java solution | my-java-solution-by-vvgusser-cma3 | \nprivate static final Map<Character, Integer> NUMS = new HashMap<Character, Integer>(){{\n put(\'I\', 1);\n put(\'V\', 5);\n put(\'X\', 10);\n put( | vvgusser | NORMAL | 2018-04-13T15:13:14.279378+00:00 | 2022-05-23T12:17:46.102588+00:00 | 5,233 | false | ```\nprivate static final Map<Character, Integer> NUMS = new HashMap<Character, Integer>(){{\n put(\'I\', 1);\n put(\'V\', 5);\n put(\'X\', 10);\n put(\'L\', 50);\n put(\'C\', 100);\n put(\'D\', 500);\n put(\'M\', 1000);\n}};\n\nprivate static int convertToInt(String s) {\n\tint r = 0;\n\tint prev ... | 25 | 0 | [] | 4 |
roman-to-integer | [Java/Python] Short solution - Clean & Concise | javapython-short-solution-clean-concise-wtver | Intuitive\n- Roman numerals are usually written largest to smallest from left to right, for example: XII (7), XXVII (27), III (3)...\n- If a small value is pl | hiepit | NORMAL | 2021-02-20T08:59:03.973154+00:00 | 2021-02-20T10:15:22.367556+00:00 | 1,093 | false | **Intuitive**\n- Roman numerals are usually written largest to smallest from left to right, for example: `XII (7)`, `XXVII (27)`, `III (3)`...\n- If a small value is placed before a bigger value then it\'s a combine number, for exampe: `IV (4)`, `IX (9)`, `XIV (14)`...\n\n**Complexity**\n- Time: `O(N)`, where `N <= 1... | 24 | 4 | [] | 1 |
roman-to-integer | ✅Beats 100% | Explained Step by Step | List Most Common String Interview Problems✅ | beats-100-explained-step-by-step-list-mo-zqd8 | Aproach 1: pattern matching + calc_scale\npython3 []\nclass Solution:\n @staticmethod\n def calc_scale(c: str, a1: str, a2: str) -> int:\n return - | Piotr_Maminski | NORMAL | 2024-11-07T23:13:12.727030+00:00 | 2024-11-08T14:12:07.634556+00:00 | 7,919 | false | # Aproach 1: pattern matching + calc_scale\n```python3 []\nclass Solution:\n @staticmethod\n def calc_scale(c: str, a1: str, a2: str) -> int:\n return -1 if c == a1 or c == a2 else 1\n \n def romanToInt(self, s: str) -> int:\n result = 0\n \n for n in range(len(s)):\n ... | 23 | 0 | ['Swift', 'C', 'C++', 'Java', 'TypeScript', 'Python3', 'Rust', 'Ruby', 'JavaScript', 'C#'] | 5 |
roman-to-integer | ✅ Beats 100% 🔥Iterative Convertion Approach || Java || Rust || C++ || Python | beats-100-iterative-convertion-approach-s36u2 | Intuition\nThe solution aims to convert a Roman numeral representation into its corresponding integer value. It utilizes the properties of Roman numerals, such | farhanzamanarnob | NORMAL | 2024-03-18T09:09:33.988612+00:00 | 2024-03-18T09:09:33.988631+00:00 | 2,882 | false | # Intuition\nThe solution aims to convert a Roman numeral representation into its corresponding integer value. It utilizes the properties of Roman numerals, such as the rules of addition. \n\n\n\n# Approach... | 23 | 0 | ['Java'] | 5 |
roman-to-integer | ✅Short || C++ || Java || PYTHON || Explained Solution✔️ || Beginner Friendly ||🔥 🔥 BY MR CODER | short-c-java-python-explained-solution-b-upji | Please UPVOTE if you LIKE!!\nWatch this video \uD83E\uDC83 for the better explanation of the code.\n\nhttps://www.youtube.com/watch?v=Nc35iWWqT78\n\n\nAlso you | mrcoderrm | NORMAL | 2022-08-15T10:16:04.843977+00:00 | 2022-08-15T10:31:48.736253+00:00 | 3,835 | false | **Please UPVOTE if you LIKE!!**\n**Watch this video \uD83E\uDC83 for the better explanation of the code.**\n\nhttps://www.youtube.com/watch?v=Nc35iWWqT78\n\n\n**Also you can SUBSCRIBE \uD83E\uDC81 \uD83E\uDC81 \uD83E\uDC81 this channel for the daily leetcode challange solution.**\n**C++**\n```\nclass Solution {\npubli... | 23 | 0 | ['C', 'Python', 'Java'] | 1 |
roman-to-integer | php (using str_tr) | php-using-str_tr-by-thepowerofcreation21-2d0p | so i did this and it worked :)\n\n\nclass Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function romanToInt($s) {\n | thePowerOfCreation21 | NORMAL | 2022-06-26T14:56:32.532842+00:00 | 2022-06-26T14:56:32.532885+00:00 | 1,445 | false | so i did this and it worked :)\n\n```\nclass Solution {\n\n /**\n * @param String $s\n * @return Integer\n */\n function romanToInt($s) {\n $s = strtr(\n $s,\n [\n \'M\' => \'1000,\',\n \'CM\' => \'900,\',\n \'D\' => \'500,\',\n... | 23 | 0 | ['PHP'] | 4 |
roman-to-integer | Easy to understand w/ explanation | 12 lines | Faster than 98% | easy-to-understand-w-explanation-12-line-3zbn | Approach:\n1. Scan the given roman numeral string from left to right character by character and add the corresponding integer value to ans.\n2. Record previous | v21 | NORMAL | 2021-03-28T11:44:48.491316+00:00 | 2021-05-13T11:28:50.501106+00:00 | 1,589 | false | **Approach:**\n1. Scan the given roman numeral string from left to right character by character and add the corresponding integer value to `ans`.\n2. Record previous added value in `prev` so that it can be compared with another value in the next iteration. If `curr` value is greater than `prev`, it means we have numera... | 23 | 0 | ['Python', 'Python3'] | 3 |
roman-to-integer | Easiest Map Solution C++ | easiest-map-solution-c-by-schwjustin-wxor | \nclass Solution {\npublic:\n int romanToInt(string s) {\n unordered_map <char, int> dict {\n {\'I\', 1},\n {\'V\', 5},\n | schwjustin | NORMAL | 2020-06-25T15:03:36.846941+00:00 | 2020-06-25T15:03:36.846990+00:00 | 2,999 | false | ```\nclass Solution {\npublic:\n int romanToInt(string s) {\n unordered_map <char, int> dict {\n {\'I\', 1},\n {\'V\', 5},\n {\'X\', 10},\n {\'L\', 50},\n {\'C\', 100},\n {\'D\', 500},\n {\'M\', 1000},\n };\n \n ... | 23 | 0 | ['C', 'C++'] | 4 |
roman-to-integer | C++: Fast & Easy to understand: 4ms (98%) 8.3MB (90%) | c-fast-easy-to-understand-4ms-98-83mb-90-jmb3 | \nclass Solution {\npublic:\n int romanToInt(string s) {\n int ret = 0; // to store the return value\n int temp = 0; // to store t | kellyckj | NORMAL | 2019-08-26T07:40:01.247117+00:00 | 2019-08-27T03:22:04.141640+00:00 | 4,099 | false | ```\nclass Solution {\npublic:\n int romanToInt(string s) {\n int ret = 0; // to store the return value\n int temp = 0; // to store the previous value\n \n for (size_t i = 0; i < s.size(); i++) {\n char curr = s[i];\n int pos = 0; // to store the cur... | 23 | 3 | ['C', 'C++'] | 1 |
roman-to-integer | C simple and easy solution.. | c-simple-and-easy-solution-by-kaviyapriy-f7z9 | \n\n# Code\n\n\nint DecimalNumericalPlace(char roman_np_value)\n {\n switch(roman_np_value)\n {\n case \'M\':\n return 10 | kaviyapriya_03 | NORMAL | 2023-03-01T10:22:25.716415+00:00 | 2023-03-01T10:22:25.716460+00:00 | 8,381 | false | \n\n# Code\n```\n\nint DecimalNumericalPlace(char roman_np_value)\n {\n switch(roman_np_value)\n {\n case \'M\':\n return 1000;\n break;\n\n case \'D\':\n return 500;\n break;\n\n case \'C\':\n return 100;\n ... | 22 | 0 | ['C'] | 4 |
roman-to-integer | [PYTHON 3] BEATS 99.13% | EASY TO UNDERSTAND | python-3-beats-9913-easy-to-understand-b-9n4c | Runtime: 44 ms, faster than 99.13% of Python3 online submissions for Roman to Integer.\nMemory Usage: 13.9 MB, less than 76.17% of Python3 online submissions fo | omkarxpatel | NORMAL | 2022-07-12T15:31:39.381550+00:00 | 2022-10-04T05:21:31.955047+00:00 | 2,981 | false | Runtime: **44 ms, faster than 99.13%** of Python3 online submissions for Roman to Integer.\nMemory Usage: **13.9 MB, less than 76.17%** of Python3 online submissions for Roman to Integer.\n```\nclass Solution:\n def romanToInt(self, s: str) -> int:\n a, r = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 50... | 22 | 0 | ['Python', 'Python3'] | 9 |
roman-to-integer | ✔️ 100% Fastest Swift Solution | 100-fastest-swift-solution-by-sergeylesc-kswk | \nclass Solution {\n func romanToInt(_ s: String) -> Int {\n\t\tvar num: Int = 0\n\t\tvar prev: Character = " "\n\t\tlet map: [Character : Int] = [\n\t\t\t"I | sergeyleschev | NORMAL | 2022-03-31T05:39:35.389723+00:00 | 2022-03-31T05:39:35.389746+00:00 | 4,193 | false | ```\nclass Solution {\n func romanToInt(_ s: String) -> Int {\n\t\tvar num: Int = 0\n\t\tvar prev: Character = " "\n\t\tlet map: [Character : Int] = [\n\t\t\t"I": 1,\n\t\t\t"V": 5,\n\t\t\t"X": 10,\n\t\t\t"L": 50,\n\t\t\t"C": 100,\n\t\t\t"D": 500,\n\t\t\t"M": 1000,\n\t\t]\n\t\t \n\t\tfor c in s {\n\t\t\tif pre... | 22 | 4 | ['Swift'] | 2 |
roman-to-integer | Kotlin simple | kotlin-simple-by-georgcantor-ktvz | \nfun romanToInt(s: String): Int {\n val map = mutableMapOf(\n \'I\' to 1, \'V\' to 5, \'X\' to 10, \'L\' to 50, \'C\' to 100, \'D\' to 500, \ | GeorgCantor | NORMAL | 2021-02-08T14:06:24.883589+00:00 | 2021-02-08T14:06:24.883620+00:00 | 2,892 | false | ```\nfun romanToInt(s: String): Int {\n val map = mutableMapOf(\n \'I\' to 1, \'V\' to 5, \'X\' to 10, \'L\' to 50, \'C\' to 100, \'D\' to 500, \'M\' to 1000\n )\n var number = 0\n var last = 1000\n s.forEach {\n val value = map[it] ?: 0\n if (value > ... | 22 | 0 | ['Kotlin'] | 5 |
roman-to-integer | JavaScript simple decrementing while loop | javascript-simple-decrementing-while-loo-x6bk | \n/**\n * @param {string} s\n * @return {number}\n */\nvar romanToInt = function(s) {\n const map = {\n I: 1,\n V: 5,\n X: 10,\n | pdxandi | NORMAL | 2018-08-19T16:45:52.962602+00:00 | 2018-10-18T21:47:22.214741+00:00 | 1,480 | false | ```\n/**\n * @param {string} s\n * @return {number}\n */\nvar romanToInt = function(s) {\n const map = {\n I: 1,\n V: 5,\n X: 10,\n L: 50,\n C: 100,\n D: 500,\n M: 1000\n };\n let i = s.length;\n let result = 0;\n \n while (i--) {\n const curr = ... | 21 | 0 | [] | 2 |
roman-to-integer | [JAVA] 3-4 liner solution using switch case | java-3-4-liner-solution-using-switch-cas-kzha | \nclass Solution {\n public int romanToInt(String s) {\n int ans = 0, num = 0;\n for(int i = s.length() - 1; i >= 0; i --) {\n switch(s.char | Jugantar2020 | NORMAL | 2022-08-15T05:15:14.037678+00:00 | 2022-08-15T05:15:14.037723+00:00 | 1,669 | false | ```\nclass Solution {\n public int romanToInt(String s) {\n int ans = 0, num = 0;\n for(int i = s.length() - 1; i >= 0; i --) {\n switch(s.charAt(i)) {\n case \'I\' : num = 1; break;\n case \'V\' : num = 5; break;\n case \'X\' : num = 10; break;\n case \'L\' : num... | 19 | 2 | ['Java'] | 3 |
roman-to-integer | Rust | "One-Liner" | With Comments | rust-one-liner-with-comments-by-wallicen-k2s8 | EDIT 2022-08-15: Celebrating that this is the problem of the day by doing a more elegant and fully functional solution. As hinted below in the original solution | wallicent | NORMAL | 2022-06-27T13:32:44.067734+00:00 | 2022-08-16T14:32:58.206111+00:00 | 2,163 | false | EDIT 2022-08-15: Celebrating that this is the problem of the day by doing a more elegant and fully functional solution. As hinted below in the original solution, I use a state machine approach to avoid complicating things with having to look at pairs. My definition of a one-liner is that are no semicolons ending expres... | 19 | 0 | ['Rust'] | 1 |
roman-to-integer | [Java/C++/Python]O(n)time/BEATS 99.97% MEMORY/SPEED 0ms APRIL 2022 | javacpythonontimebeats-9997-memoryspeed-h0m3f | C++\n\nclass Solution {\npublic:\n int romanToInt(string S) {\n int ans = 0, num = 0;\n for (int i = S.size()-1; ~i; i--) {\n switch | darian-catalin-cucer | NORMAL | 2022-04-24T20:40:28.998939+00:00 | 2022-04-24T20:40:28.998984+00:00 | 2,429 | false | ***C++***\n```\nclass Solution {\npublic:\n int romanToInt(string S) {\n int ans = 0, num = 0;\n for (int i = S.size()-1; ~i; i--) {\n switch(S[i]) {\n case \'I\': num = 1; break;\n case \'V\': num = 5; break;\n case \'X\': num = 10; break;\n ... | 19 | 0 | ['C', 'Combinatorics', 'Python', 'C++', 'Java'] | 4 |
roman-to-integer | Python3 - The way the Romans do it | python3-the-way-the-romans-do-it-by-ichb-e902 | Here is my solution. Beat 99.43% of submissions.\n\n1. Iterate through the string from right to left. \n2. Whenever the current letter is larger than the previo | ichbinik | NORMAL | 2017-11-28T05:08:50.733000+00:00 | 2017-11-28T05:08:50.733000+00:00 | 3,421 | false | Here is my solution. Beat 99.43% of submissions.\n\n1. Iterate through the string from right to left. \n2. Whenever the current letter is larger than the previous letter, add it to the total. \n3. Whenever the current letter is smaller than the previous, subtract it from the total.\n\n```\nclass Solution:\n\n charTo... | 19 | 0 | [] | 3 |
roman-to-integer | Straightforward Java Solution Using Recursion (139ms) | straightforward-java-solution-using-recu-yhft | \nclass Solution\n{\n public int romanToInt(String s)\n {\n if(s.length() == 0) return 0;\n \n if(s.length() > 1)\n {\n | aeriagloris | NORMAL | 2017-12-22T20:47:32.234000+00:00 | 2017-12-22T20:47:32.234000+00:00 | 7,558 | false | ```\nclass Solution\n{\n public int romanToInt(String s)\n {\n if(s.length() == 0) return 0;\n \n if(s.length() > 1)\n {\n if(s.substring(0,2).equals("CM")) return 900 + romanToInt(s.substring(2));\n if(s.substring(0,2).equals("CD")) return 400 + romanToInt(... | 19 | 0 | [] | 0 |
roman-to-integer | [VIDEO] Visualization of Two Different Approaches | video-visualization-of-two-different-app-jmnf | https://www.youtube.com/watch?v=tsmrUi5M1JU\n\nMethod 1:\nThis solution takes the approach incorporating the general logic of roman numerals into the algorithm. | AlgoEngine | NORMAL | 2024-09-06T23:30:50.963594+00:00 | 2024-09-06T23:30:50.963624+00:00 | 1,439 | false | https://www.youtube.com/watch?v=tsmrUi5M1JU\n\n<b>Method 1:</b>\nThis solution takes the approach incorporating the general logic of roman numerals into the algorithm. We first create a dictionary that maps each roman numeral to the corresponding integer. We also create a total variable set to 0.\n\nWe then loop over... | 18 | 0 | ['Hash Table', 'Math', 'String', 'Python', 'Python3'] | 2 |
roman-to-integer | Python, C++, Java Easy solution 87.30% | python-c-java-easy-solution-8730-by-naga-qudu | \u2705Below code is in python same approach for C++ and JAVA\nPlease UPVOTE if u like the CODE (^_^)\n\nTime Complexity O(n)\n\nPlease UPVOTE (^_^)\n\n\nclass S | Nagadinesh99 | NORMAL | 2022-08-29T18:04:50.885282+00:00 | 2022-08-29T18:05:18.937801+00:00 | 2,915 | false | **\u2705Below code is in python same approach for C++ and JAVA\nPlease UPVOTE if u like the CODE (^_^)**\n\n**Time Complexity O(n)**\n\n**Please UPVOTE (^_^)**\n\n```\nclass Solution:\n def romanToInt(self, s: str) -> int:\n d={\'I\':1,\'V\':5,\'X\':10,\'L\':50,\'C\':100,\'D\':500,\'M\':1000}\n c=0\n ... | 18 | 0 | ['Hash Table', 'C', 'Python', 'Java'] | 1 |
roman-to-integer | ✔️4 easy solution Explained | Beginner-friendly | Dictionary, Arithmetic logic | 4-easy-solution-explained-beginner-frien-w2lv | \nBrutal force:\n In this solution, we just need a bunch of if statement.\n If we encounter I, we need to check if there are V and X after it.\n If we encounte | luluboy168 | NORMAL | 2022-08-15T01:32:57.726010+00:00 | 2022-08-15T15:11:21.133751+00:00 | 925 | false | \n**Brutal force:**\n* In this solution, we just need a bunch of if statement.\n* If we encounter `I`, we need to check if there are `V` and `X` after it.\n* If we encounter `X`, we need to check if there are `L` and `C` after it.\n* If we encounter `C`, we need to check if there are `D` and `M` after it.\n```\nclas... | 18 | 0 | [] | 1 |
roman-to-integer | Easiest C++ code explained with comments|| HashMap approach | easiest-c-code-explained-with-comments-h-j2et | Here is my complete code, explained with comments at each step. Just go through the code and you will easily get this.\nAlso Upvote, if this helps.\n\n\nclass S | algoBreaker018 | NORMAL | 2022-03-21T17:59:40.759033+00:00 | 2022-03-21T17:59:40.759086+00:00 | 1,670 | false | Here is my complete code, explained with comments at each step. Just go through the code and you will easily get this.\nAlso Upvote, if this helps.\n\n```\nclass Solution {\npublic:\n int romanToInt(string s) {\n // creating a map to store the character and its value\n unordered_map<char,int> m;\n ... | 18 | 0 | ['C'] | 2 |
roman-to-integer | [Python] short solution, explained | python-short-solution-explained-by-dbabi-qr2x | Let us calculate number in two steps:\n\n1. We know that I equal to 1, V equal to 5 and so on, so let us just iterate over string and add value to final answer. | dbabichev | NORMAL | 2021-02-20T09:34:36.099375+00:00 | 2021-02-20T09:34:36.099429+00:00 | 528 | false | Let us calculate number in two steps:\n\n1. We know that `I` equal to `1`, `V` equal to `5` and so on, so let us just iterate over string and add value to final answer.\n2. There is something we need to fix now, for example if we have `IX`, it is equal to `9`, but we added `11`, so we need to subtract `2`. Similar for ... | 18 | 6 | [] | 1 |
roman-to-integer | C++ // 100% | c-100-by-paulsepolia-vmhb | class Solution \n{\n private:\n \n int fun(const char a)\n {\n if(a == \'I\') return 1;\n if(a == \'V\') return 5;\n if(a == \' | paulsepolia | NORMAL | 2020-01-21T16:10:19.984308+00:00 | 2020-01-21T16:10:19.984356+00:00 | 2,862 | false | class Solution \n{\n private:\n \n int fun(const char a)\n {\n if(a == \'I\') return 1;\n if(a == \'V\') return 5;\n if(a == \'X\') return 10;\n if(a == \'L\') return 50;\n if(a == \'C\') return 100;\n if(a == \'D\') return 500;\n if(a == \'M\') return 1000;\... | 18 | 0 | ['C', 'C++'] | 2 |
roman-to-integer | Simple 56ms C++ solution | simple-56ms-c-solution-by-deck-1b8k | Processing the roman number from right to left turns out to be a bit easier since we can easily tell when to add or subtract:\n\n class Solution {\n publi | deck | NORMAL | 2015-06-01T19:11:56+00:00 | 2015-06-01T19:11:56+00:00 | 4,015 | false | Processing the roman number from right to left turns out to be a bit easier since we can easily tell when to add or subtract:\n\n class Solution {\n public:\n int romanToInt(string s) {\n if (s.empty()) { return 0; }\n unordered_map<char, int> mp { {'I', 1}, {'V', 5}, {'X', 10}, {'L',... | 18 | 2 | ['C++'] | 2 |
roman-to-integer | Easy to understand JAVA | easy-to-understand-java-by-junbo1226-4ehx | ```\nclass Solution {\n public int romanToInt(String s) {\n HashMap m = new HashMap();\n m.put('I',1);\n m.put('V',5);\n m.put('X | junbo1226 | NORMAL | 2017-12-20T18:09:48.541000+00:00 | 2017-12-20T18:09:48.541000+00:00 | 7,636 | false | ```\nclass Solution {\n public int romanToInt(String s) {\n HashMap<Character, Integer> m = new HashMap<Character, Integer>();\n m.put('I',1);\n m.put('V',5);\n m.put('X',10);\n m.put('L',50);\n m.put('C',100);\n m.put('D',500);\n m.put('M',1000);\n char... | 18 | 0 | [] | 0 |
roman-to-integer | ✨ 0ms | 🏆 Beats 100% | C++ 🖥️ , Python 🐍, Java ☕, Go 🐹, JS 🚀 | Roman to Integer Conversion 🏅 | 0ms-beats-100-c-python-java-go-js-roman-27c1j | IntuitionThe Roman numeral system is based on additive and subtractive rules. To convert a Roman numeral to an integer, we can iterate through the string from l | Raza-Jaun | NORMAL | 2024-12-18T15:43:43.939519+00:00 | 2024-12-18T15:43:43.939519+00:00 | 1,861 | false | # Intuition\nThe Roman numeral system is based on additive and subtractive rules. To convert a Roman numeral to an integer, we can iterate through the string from left to right and apply the subtractive rule when a smaller value precedes a larger one, otherwise, we simply add the value.\n\n---\n\n\n# Approach\nWe use a... | 17 | 0 | ['Hash Table', 'Math', 'String', 'C++', 'Java', 'Go', 'Python3', 'JavaScript'] | 0 |
roman-to-integer | O(n) solution || Easy || String || HashMap | on-solution-easy-string-hashmap-by-tejas-dpqd | Intuition\n Describe your first thoughts on how to solve this problem. \nwe have to store roman values first at a place to calculate the value\n# Approach\n Des | tejasvi_18_08 | NORMAL | 2023-01-05T13:20:52.101730+00:00 | 2023-01-22T01:55:29.782877+00:00 | 6,181 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nwe have to store roman values first at a place to calculate the value\n# Approach\n<!-- Describe your approach to solving the problem. -->\nStored elements in hashmap\ntraversed string from back,if current element is of less value than th... | 17 | 0 | ['Java'] | 1 |
roman-to-integer | Java || Explained || fastest || loops | java-explained-fastest-loops-by-sharad21-9vhv | \n\nclass Solution {\n public int romanToInt(String s) {\n \n int[] ar = new int[s.length()];\n \n\t\t//we store the value in array so it | Sharad21 | NORMAL | 2022-07-18T20:32:58.224408+00:00 | 2022-07-20T16:49:40.925765+00:00 | 804 | false | ```\n\n```class Solution {\n public int romanToInt(String s) {\n \n int[] ar = new int[s.length()];\n \n\t\t//we store the value in array so it easy for us to add numbers\n for(int i=0;i<ar.length;i++){\n char c = s.charAt(i);\n switch(c){\n case \'I\' :... | 17 | 0 | [] | 0 |
roman-to-integer | Python Super-Simple Easy-to-Understand Explained Solution | python-super-simple-easy-to-understand-e-yewm | \nclass Solution:\n def romanToInt(self, s: str) -> int:\n num_dict = { \'I\' : 1,\n \'V\' : 5,\n \'X\' | yehudisk | NORMAL | 2021-02-20T18:04:30.590559+00:00 | 2021-02-20T18:04:30.590614+00:00 | 850 | false | ```\nclass Solution:\n def romanToInt(self, s: str) -> int:\n num_dict = { \'I\' : 1,\n \'V\' : 5,\n \'X\' : 10,\n \'L\' : 50,\n \'C\' : 100,\n \'D\' : 500,\n \'M\' : 1000 }\n ... | 17 | 1 | ['Python3'] | 1 |
roman-to-integer | C Solution | c-solution-by-ianchen0119-laod | Runtime: 4 ms, faster than 87.28% of C online submissions for Roman to Integer.\nMemory Usage: 5.8 MB, less than 98.48% of C online submissions for Roman to Int | ianchen0119 | NORMAL | 2020-12-15T10:10:04.338483+00:00 | 2020-12-15T10:17:52.065378+00:00 | 2,651 | false | Runtime: 4 ms, faster than 87.28% of C online submissions for Roman to Integer.\nMemory Usage: 5.8 MB, less than 98.48% of C online submissions for Roman to Integer.\n```c=\nint value(char opcode){\n switch(opcode){\n case \'I\': \n return 1;\n case \'V\': \n return 5;\n ... | 17 | 0 | [] | 1 |
roman-to-integer | Ruby solution 52ms | ruby-solution-52ms-by-ayamschikov-vovd | Ruby solution with\n\t- Runtime: 52 ms\n\t- Memory Usage: 9.3 MB\n\ndef roman_to_int(s)\n hash = {\n \'I\'=> 1,\n \'V\'=> 5,\n \'X\'=> 10,\n \'L\'= | ayamschikov | NORMAL | 2019-11-07T17:08:38.736312+00:00 | 2019-11-07T17:08:38.736348+00:00 | 2,997 | false | Ruby solution with\n\t- Runtime: 52 ms\n\t- Memory Usage: 9.3 MB\n```\ndef roman_to_int(s)\n hash = {\n \'I\'=> 1,\n \'V\'=> 5,\n \'X\'=> 10,\n \'L\'=> 50,\n \'C\'=> 100,\n \'D\'=> 500,\n \'M\'=> 1000\n }\n\n total = 0\n i = 0\n while i < s.length\n if i + 1 < s.length && hash[s[i]] < hash[... | 17 | 1 | ['Ruby'] | 4 |
roman-to-integer | Simple javascript solution | simple-javascript-solution-by-hadleyac-qc49 | \nvar romanToInt = function(s) {\n let table = {\n I: 1,\n V: 5,\n X: 10,\n L: 50,\n C: 100,\n D: 500,\n M: | hadleyac | NORMAL | 2019-09-02T22:15:32.525783+00:00 | 2019-09-02T22:15:32.525817+00:00 | 5,810 | false | ```\nvar romanToInt = function(s) {\n let table = {\n I: 1,\n V: 5,\n X: 10,\n L: 50,\n C: 100,\n D: 500,\n M: 1000\n }\n \n let result = 0;\n for (let i = 0; i < s.length; i++) {\n //if the next roman numeral is larger, then we know we have to subt... | 17 | 1 | [] | 5 |
roman-to-integer | ✅Step By Steps Solution 🔥|| Best Method ✅ || Beats 100% User ✅ || Beginner Friendly🔥🔥🔥 | step-by-steps-solution-best-method-beats-yzq8 | Intuition :\nThe main idea behind converting a Roman numeral to an integer is to look for specific patterns of subtraction. For instance, when a smaller numeral | progammersoumen | NORMAL | 2024-10-27T09:55:00.748244+00:00 | 2024-10-27T09:55:00.748266+00:00 | 2,960 | false | ### Intuition :\nThe main idea behind converting a Roman numeral to an integer is to look for specific patterns of subtraction. For instance, when a smaller numeral appears before a larger one (like IV for 4 or IX for 9), it implies a subtraction. Otherwise, the Roman numerals are simply added in descending order.\n\n#... | 16 | 0 | ['Hash Table', 'Math', 'C++', 'Java', 'Python3'] | 0 |
roman-to-integer | ✔️Python 99%🔥 Beginner-friendly 4 solution explained | easy to understand | python-99-beginner-friendly-4-solution-e-groa | Brutal force:\n In this solution, we just need a bunch of if statement.\n If we encounter I, we need to check if there are V and X after it.\n If we encounter | luluboy168 | NORMAL | 2022-08-15T15:05:22.624865+00:00 | 2022-08-15T15:05:22.624894+00:00 | 1,076 | false | **Brutal force:**\n* In this solution, we just need a bunch of if statement.\n* If we encounter `I`, we need to check if there are `V` and `X` after it.\n* If we encounter `X`, we need to check if there are `L` and `C` after it.\n* If we encounter `C`, we need to check if there are `D` and `M` after it.\n```\nclass ... | 16 | 0 | ['Python'] | 0 |
diagonal-traverse-ii | [Clean, Simple] Easiest Explanation with a picture and code with comments | clean-simple-easiest-explanation-with-a-72abg | Key Idea\nIn a 2D matrix, elements in the same diagonal have same sum of their indices.\n\n\n\n\n\nSo if we have all elements with same sum of their indices tog | interviewrecipes | NORMAL | 2020-04-26T04:03:10.830708+00:00 | 2020-08-08T05:22:49.226540+00:00 | 21,004 | false | **Key Idea**\nIn a 2D matrix, elements in the same diagonal have same sum of their indices.\n\n\n\n\n\nSo if we have all elements with same sum of their indices together, then it\u2019s just a matter of printing those elements in order.\n\... | 581 | 0 | [] | 49 |
diagonal-traverse-ii | [Java/C++] HashMap with Picture - Clean code - O(N) | javac-hashmap-with-picture-clean-code-on-tr0o | Example:\n\n\nJava\njava\nclass Solution {\n public int[] findDiagonalOrder(List<List<Integer>> nums) {\n int n = 0, i = 0, maxKey = 0;\n Map<I | hiepit | NORMAL | 2020-04-26T04:01:24.287061+00:00 | 2020-04-26T07:41:49.736870+00:00 | 14,153 | false | Example:\n\n\n**Java**\n```java\nclass Solution {\n public int[] findDiagonalOrder(List<List<Integer>> nums) {\n int n = 0, i = 0, maxKey = 0;\n Map<Integer, List<Integer>> map = new HashMap<>();\n for (int r = nums.size() - ... | 173 | 2 | [] | 23 |
diagonal-traverse-ii | [Python] Simple BFS solution with detailed explanation | python-simple-bfs-solution-with-detailed-5vgh | Explanation\nWe can think of the given matrix as a tree and use BFS to solve this problem.\n\nThe top-left number, nums[0][0], is the root node. nums[1][0] is | alanlzl | NORMAL | 2020-04-26T04:00:51.115073+00:00 | 2020-04-26T04:00:51.115126+00:00 | 4,352 | false | **Explanation**\nWe can think of the given matrix as a tree and use BFS to solve this problem.\n\nThe top-left number, `nums[0][0]`, is the root node. `nums[1][0]` is its left child and `nums[0][1]` is its right child. Same analogy applies to all nodes `nums[i][j]`.\n\nNote that `nums[i][j]` is both the left child of ... | 146 | 0 | [] | 15 |
diagonal-traverse-ii | [Python] One pass | python-one-pass-by-lee215-p66y | Time O(A), Space O(A)\n\nPython:\npy\n def findDiagonalOrder(self, A):\n res = []\n for i, r in enumerate(A):\n for j, a in enumerat | lee215 | NORMAL | 2020-04-26T04:08:14.947205+00:00 | 2020-04-26T04:08:14.947251+00:00 | 10,993 | false | Time `O(A)`, Space `O(A)`\n\n**Python:**\n```py\n def findDiagonalOrder(self, A):\n res = []\n for i, r in enumerate(A):\n for j, a in enumerate(r):\n if len(res) <= i + j:\n res.append([])\n res[i + j].append(a)\n return [a for r in re... | 121 | 7 | [] | 20 |
diagonal-traverse-ii | Simple Solution || Beginner Friendly || Easy to Understand ✅ | simple-solution-beginner-friendly-easy-t-vh30 | Approach\n Describe your approach to solving the problem. \nInitialization:\n- Initialize a variable count to keep track of the total number of elements in the | Anirban_Pramanik10 | NORMAL | 2023-11-22T00:30:02.763669+00:00 | 2023-11-22T00:30:02.763693+00:00 | 15,011 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\n$$Initialization:$$\n- Initialize a variable `count` to keep track of the total number of elements in the result array.\n- Create an ArrayList of ArrayLists called `lists` to store the elements diagonally.\n\n$$Traversing the Matrix Diagonally:$$\n- U... | 95 | 3 | ['Array', 'Linked List', 'Depth-First Search', 'Breadth-First Search', 'C', 'Python', 'C++', 'Java', 'Python3', 'JavaScript'] | 6 |
diagonal-traverse-ii | [C++] Single pass solution using BFS, 308ms (99.72%) | c-single-pass-solution-using-bfs-308ms-9-e71u | I couldn\'t find any truly single pass solution in the discussions. Here is my approach (using BFS).\nAlgorithm-\n1. In the queue for BFS, insert the index for | kunal_mohta | NORMAL | 2020-04-27T03:41:54.324705+00:00 | 2020-04-27T03:41:54.324753+00:00 | 2,428 | false | I couldn\'t find any truly single pass solution in the discussions. Here is my approach (using BFS).\nAlgorithm-\n1. In the queue for BFS, insert the index for first cell of first row, i.e. `{0,0}`\n2. For each iteration, for the `front` element in queue push the index for cell just below it only if the current cell is... | 49 | 0 | [] | 6 |
diagonal-traverse-ii | 【Video】Give me 9 minutes - How we think about a solution | video-give-me-9-minutes-how-we-think-abo-6m4v | Intuition\nUsing BFS\n\n---\n\n# Solution Video\n\nhttps://youtu.be/4wkt4kGip64\n\n\u25A0 Timeline of the video\n0:04 How we think about a solution\n1:08 How ca | niits | NORMAL | 2023-11-22T09:22:16.755166+00:00 | 2023-11-23T17:47:37.638368+00:00 | 2,277 | false | # Intuition\nUsing BFS\n\n---\n\n# Solution Video\n\nhttps://youtu.be/4wkt4kGip64\n\n\u25A0 Timeline of the video\n`0:04` How we think about a solution\n`1:08` How can you put numbers into queue with right order?\n`2:34` Demonstrate how it works\n`6:24` Summary of main idea\n`6:47` Coding\n`8:40` Time Complexity and Sp... | 42 | 0 | ['C++', 'Java', 'Python3', 'JavaScript'] | 3 |
diagonal-traverse-ii | 🍀 C++ || SIMPLE BFS 🍀 | c-simple-bfs-by-datt_21-malz | Intuition\n- First element can be considered as root and the rest are just children of the root. \n\n# Code\n\nclass Solution {\npublic:\n vector<int> findDi | datt_21 | NORMAL | 2023-11-22T06:20:39.730413+00:00 | 2023-11-22T06:20:39.730437+00:00 | 2,376 | false | # Intuition\n- First element can be considered as `root` and the rest are just children of the `root`. \n\n# Code\n```\nclass Solution {\npublic:\n vector<int> findDiagonalOrder(vector<vector<int>>& v) {\n int n = v.size();\n queue<pair<int, int>> q;\n vector<int> ans;\n\n q.push( {0, 0} ... | 27 | 0 | ['Array', 'Tree', 'Queue', 'Binary Tree', 'C++'] | 4 |
diagonal-traverse-ii | ✅ One Line Solution | one-line-solution-by-mikposp-gv79 | (Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)Code #1.1 - OnelinerTime complexity: O(n∗log(n)). Sp | MikPosp | NORMAL | 2023-11-22T08:55:39.449347+00:00 | 2025-02-17T17:32:33.744678+00:00 | 717 | false | (Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)
# Code #1.1 - Oneliner
Time complexity: $$O(n*log(n))$$. Space complexity: $$O(n)$$.
```
class Solution:
def findDiagonalOrder(self, a: List[List[int]]) -> List[int]:
return [v for _,_,v in sorted((... | 23 | 0 | ['Array', 'Sorting', 'Python', 'Python3'] | 1 |
diagonal-traverse-ii | C++ beat 99.9% BFS concise solution with explanation | c-beat-999-bfs-concise-solution-with-exp-x2uw | This problem is similar to "level order traverse of a tree". \n Recap:\n what matters is the order by which the "neighbor node" is added. The node in the first | veronicatt | NORMAL | 2020-10-25T20:06:32.414673+00:00 | 2020-10-25T20:08:58.158769+00:00 | 1,266 | false | This problem is similar to "level order traverse of a tree". \n Recap:\n* what matters is the order by which the "neighbor node" is added. The node in the first column is special, because it can generate two "neighbor nodes": the node below and the node to its right. For all other nodes, they can only generate the nod... | 17 | 0 | ['C'] | 2 |
diagonal-traverse-ii | ✅ Logic & Approach Explained through image | Very Easy and Short Code | | logic-approach-explained-through-image-v-d99e | \n\n\n# Please upvote if you understand the intuition well.\n\n# Complexity\n- Time complexity: O(n) Here, \'n\' will be total time, (row * column). Becuase the | yash_vish87 | NORMAL | 2023-11-22T02:29:32.652068+00:00 | 2023-11-22T02:32:27.799443+00:00 | 1,670 | false | \n\n\n# **Please upvote if you understand the intuition well.**\n\n# Complexity\n- Time complexity: $$O(n)$$ Here, \'n\' will be total time, (row * column). Becuase the input is jagged array, so included... | 16 | 0 | ['Array', 'Matrix', 'Simulation', 'Java'] | 4 |
diagonal-traverse-ii | [C++] Treemap O(n lg n) / Two-Passes O(n) | c-treemap-on-lg-n-two-passes-on-by-orang-yx9j | cpp\nclass Solution {\npublic:\n vector<int> findDiagonalOrder(vector<vector<int>>& nums) {\n // Time Complexity: O(n log n)\n // Space Complex | orangezeit | NORMAL | 2020-04-26T04:02:06.552842+00:00 | 2020-04-29T04:23:38.687839+00:00 | 1,304 | false | ```cpp\nclass Solution {\npublic:\n vector<int> findDiagonalOrder(vector<vector<int>>& nums) {\n // Time Complexity: O(n log n)\n // Space Complexity: O(n)\n \n map<pair<int, int>, int> diagonals;\n\t\t\n // nums[i][j] is located at position j on the (i+j)-th diagonal\n for ... | 16 | 1 | [] | 2 |
diagonal-traverse-ii | Java, list of stacks, explained | java-list-of-stacks-explained-by-gthor10-1xac | Catch 1 - for numbers on one diagonal sum of index of the list and index in the list is the same. This means we know the diagonal of the element when we travers | gthor10 | NORMAL | 2020-05-02T21:15:30.561414+00:00 | 2020-05-02T21:15:30.561450+00:00 | 1,387 | false | Catch 1 - for numbers on one diagonal sum of index of the list and index in the list is the same. This means we know the diagonal of the element when we traverse lists.\n\nCatch 2 - if we swipe from top to bottom from left to right then elements are traversed in reversed order for each diagonal. This means if we use st... | 13 | 0 | ['Java'] | 2 |
diagonal-traverse-ii | In-place BFS. Linear Time. No Separate Queues. C++ 68ms (100%), Java 13ms (100%). | in-place-bfs-linear-time-no-separate-que-qdep | Intuition\nWe need to flatten a 2D array and return the matrix in a diagonal order:\n\n\nThere can be up to $10^5$ rows consisting of up to $10^5$ elements each | sergei99 | NORMAL | 2023-11-22T13:49:11.299240+00:00 | 2023-11-22T20:13:55.671383+00:00 | 474 | false | # Intuition\nWe need to flatten a 2D array and return the matrix in a diagonal order:\n\n\nThere can be up to $10^5$ rows consisting of up to $10^5$ elements each, but no more than $10^5$ elements in total. ... | 12 | 1 | ['Array', 'Bit Manipulation', 'Breadth-First Search', 'C++', 'Java', 'Scala'] | 4 |
diagonal-traverse-ii | (●'◡'●) Dicts are OP💕.py | dicts-are-oppy-by-jyot_150-z7l5 | Intuition\nWe can definitely think on something like (i+j) elements are together\n# Code\njs\nclass Solution:\n def findDiagonalOrder(self, nums: List[List[i | jyot_150 | NORMAL | 2023-11-22T05:01:01.891757+00:00 | 2023-11-22T05:01:01.891792+00:00 | 817 | false | # Intuition\nWe can definitely think on something like (i+j) elements are together\n# Code\n```js\nclass Solution:\n def findDiagonalOrder(self, nums: List[List[int]]) -> List[int]:\n mp,ans={},[]\n for i in range(len(nums)):\n for j in range(len(nums[i])):\n if i+j not in mp:... | 12 | 2 | ['Python3'] | 5 |
diagonal-traverse-ii | [C++] Sort by sum of coordinates | c-sort-by-sum-of-coordinates-by-zhanghui-igmc | Given a list of list, return all elements of the nums in diagonal order.\n\n# Explanation\n\nIf the size of nums is small, we can directly walk on each diagonal | zhanghuimeng | NORMAL | 2020-04-26T04:04:37.530324+00:00 | 2020-04-26T04:04:37.530376+00:00 | 699 | false | Given a list of list, return all elements of the `nums` in diagonal order.\n\n# Explanation\n\nIf the size of `nums` is small, we can directly walk on each diagonal line to get the result. The time complexity is `O(n*m)`. However, `nums` is not a matrix but a list of list, and `n, m <= 10^5`, and doing so will cause TL... | 11 | 1 | [] | 3 |
diagonal-traverse-ii | [Python] Two simple solutions (dictionary or sort) - O(n) | python-two-simple-solutions-dictionary-o-3q04 | The first solution is to use dictionary. Complexity O(n)\nRecord the (r+c) as the key, then reverse list for each (r+c) and append it to the result.\n\n\tclass | lichuan199010 | NORMAL | 2020-04-26T05:05:22.714611+00:00 | 2020-04-26T15:51:37.569323+00:00 | 1,183 | false | The first solution is to use dictionary. Complexity O(n)\nRecord the (r+c) as the key, then reverse list for each (r+c) and append it to the result.\n\n\tclass Solution:\n\t\tdef findDiagonalOrder(self, nums: List[List[int]]) -> List[int]:\n\t\t\tD = collections.defaultdict(list)\n\t\t\tR = len(nums)\n\n\t\t\tfor r in ... | 10 | 0 | [] | 3 |
diagonal-traverse-ii | C++ array of deque->2D array | c-array-of-deque-2d-array-by-anwendeng-xo9v | Intuition\n Describe your first thoughts on how to solve this problem. \nUse array of deque diag to store the numbers on diagonal.\n\n2nd approach uses just 2D | anwendeng | NORMAL | 2023-11-22T00:34:37.936066+00:00 | 2023-11-22T01:56:13.082880+00:00 | 1,632 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUse array of deque `diag` to store the numbers on diagonal.\n\n2nd approach uses just 2D array( vector) which is more efficient. Then when using `copy` function adding to `ans`, use reverse iterator for `diag[i]`.\n# Approach\n<!-- Descri... | 9 | 1 | ['Array', 'Queue', 'C++'] | 1 |
diagonal-traverse-ii | USING PRIORITY_QUEUE || 50%+ ||EASY TO UNDER STAND | using-priority_queue-50-easy-to-under-st-ud1c | \n#define pi pair<pair<int,int>,int>\nclass Solution {\npublic:\n vector<int> findDiagonalOrder(vector<vector<int>>& nums) {\n priority_queue<pi,vecto | charadiyahardip | NORMAL | 2022-07-24T17:53:45.840470+00:00 | 2022-07-24T17:53:45.840517+00:00 | 788 | false | ```\n#define pi pair<pair<int,int>,int>\nclass Solution {\npublic:\n vector<int> findDiagonalOrder(vector<vector<int>>& nums) {\n priority_queue<pi,vector<pi>,greater<pi>>q;\n \n for(int i=0; i<nums.size(); i++)\n {\n for(int j=0; j<nums[i].size(); j++)\n {\n ... | 9 | 0 | ['C', 'Heap (Priority Queue)', 'C++'] | 0 |
diagonal-traverse-ii | [Python3] 5-lines really simple solution | python3-5-lines-really-simple-solution-b-18mv | \nclass Solution:\n def findDiagonalOrder(self, A: List[List[int]]) -> List[int]:\n d = defaultdict(list)\n for i in range(len(A)):\n | edtsoi430 | NORMAL | 2020-07-12T22:48:34.020664+00:00 | 2020-07-15T20:00:28.236230+00:00 | 941 | false | ```\nclass Solution:\n def findDiagonalOrder(self, A: List[List[int]]) -> List[int]:\n d = defaultdict(list)\n for i in range(len(A)):\n for j in range(len(A[i])):\n d[i+j].append(A[i][j])\n return [v for k in d.keys() for v in reversed(d[k])]\n``` | 9 | 1 | ['Python3'] | 3 |
diagonal-traverse-ii | Map Solution | CPP Solution | Intuition explained | map-solution-cpp-solution-intuition-expl-20tj | Intuition\nFor each diagonal (According to Que) sum of rowInd+colInd is same. \nEx. For given test case \n 0 1 2\n 0 [[1,2,3],\n 1 [4,5,6],\n 2 [7,8,9]]\n\n | saurav_1928 | NORMAL | 2023-11-22T00:52:42.190186+00:00 | 2023-11-22T00:52:42.190204+00:00 | 599 | false | # Intuition\nFor each diagonal (According to Que) sum of rowInd+colInd is same. \nEx. For given test case \n 0 1 2\n 0 [[1,2,3],\n 1 [4,5,6],\n 2 [7,8,9]]\n\nfor i=0,j=0 sum=0+0=0 so for sum=0 I stored all values whose rowInd+ColInd is 0 so i create vector as there may be multiple values,\n\nfor diagonal [8, 6] sum... | 8 | 0 | ['Array', 'Sorting', 'Heap (Priority Queue)', 'C++'] | 0 |
diagonal-traverse-ii | My solution in C# and some thought process | my-solution-in-c-and-some-thought-proces-y3h9 | My thought process:\nWith BFS, you always add the first element in the next row(if there is a next row) if the current element is the first of the row. For each | adaoverflow | NORMAL | 2020-04-26T04:18:22.252118+00:00 | 2020-04-26T04:22:14.563369+00:00 | 353 | false | My thought process:\nWith BFS, you always add the first element in the next row(if there is a next row) if the current element is the first of the row. For each element, add the next element in the same row if the current element is not the last of its row.\n\n\n var res = new List<int>();\n var q = new Q... | 8 | 0 | [] | 2 |
diagonal-traverse-ii | 【Video】BFS & Queue | video-bfs-queue-by-niits-9ixo | Intuition\nUsing BFS\n\n---\n\n# Solution Video\n\nhttps://youtu.be/4wkt4kGip64\n\n\u25A0 Timeline of the video\n0:04 How we think about a solution\n1:08 How ca | niits | NORMAL | 2024-03-27T04:01:47.209337+00:00 | 2024-03-27T04:01:47.209368+00:00 | 205 | false | # Intuition\nUsing BFS\n\n---\n\n# Solution Video\n\nhttps://youtu.be/4wkt4kGip64\n\n\u25A0 Timeline of the video\n`0:04` How we think about a solution\n`1:08` How can you put numbers into queue with right order?\n`2:34` Demonstrate how it works\n`6:24` Summary of main idea\n`6:47` Coding\n`8:40` Time Complexity and Sp... | 7 | 0 | ['C++', 'Java', 'Python3', 'JavaScript'] | 0 |
diagonal-traverse-ii | ✅☑[C++/Java/Python/JavaScript] || 2 Approaches || EXPLAINED🔥 | cjavapythonjavascript-2-approaches-expla-imi8 | PLEASE UPVOTE IF IT HELPED\n\n---\n\n\n# Approaches\n(Also explained in the code)\n\n\n#### Approach 1(Group Elements by the Sum of Row and Column Indices)\n1. | MarkSPhilip31 | NORMAL | 2023-11-22T10:12:26.041988+00:00 | 2023-12-10T18:59:48.337775+00:00 | 565 | false | # PLEASE UPVOTE IF IT HELPED\n\n---\n\n\n# Approaches\n**(Also explained in the code)**\n\n\n#### ***Approach 1(Group Elements by the Sum of Row and Column Indices)***\n1. **Initialization:**\n\n - **vector<int> ans;:** Initializes an empty vector to store the elements in diagonal order.\n - **unordered_map<int, ... | 6 | 0 | ['Array', 'Breadth-First Search', 'C', 'Sorting', 'Heap (Priority Queue)', 'C++', 'Java', 'Python3', 'JavaScript'] | 1 |
diagonal-traverse-ii | Beats 100% || O(N) || EASY 🔥|| LINKED LIST || HASHMAP || BEGINNER FRIENDLY | beats-100-on-easy-linked-list-hashmap-be-xfsc | Intuition\n\nLINKED LIST || HASH MAP\n\n\n- Using linked list we can add the values to first or any position in a list.\n\n- We create a hash map then we add th | dineshd7 | NORMAL | 2023-11-22T03:34:51.917320+00:00 | 2023-11-22T03:38:47.863728+00:00 | 134 | false | # Intuition\n\nLINKED LIST || HASH MAP\n\n\n- Using linked list we can add the values to first or any position in a list.\n\n- We create a hash map then we add the values to it from starting.\n\n- The list traversal is row wise.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- De... | 6 | 0 | ['Hash Table', 'Linked List', 'C', 'Python', 'C++', 'Java', 'Python3'] | 0 |
diagonal-traverse-ii | Python - dict, deque, and chain star | python-dict-deque-and-chain-star-by-hong-vtbj | \nclass Solution:\n def findDiagonalOrder(self, nums: List[List[int]]) -> List[int]:\n res = defaultdict(deque)\n for i, row in enumerate(nums) | hong_zhao | NORMAL | 2023-11-22T00:35:51.812236+00:00 | 2023-11-22T00:40:41.295155+00:00 | 732 | false | ```\nclass Solution:\n def findDiagonalOrder(self, nums: List[List[int]]) -> List[int]:\n res = defaultdict(deque)\n for i, row in enumerate(nums):\n for j, x in enumerate(row):\n res[i + j].appendleft(x)\n return chain(*res.values())\n``` | 6 | 1 | ['Python3'] | 1 |
diagonal-traverse-ii | Simple java bfs solution | simple-java-bfs-solution-by-raghu6306766-gccj | class Solution {\n \n\tpublic class Coordinate{\n int x , y;\n Coordinate(int x , int y){\n this.x = x;\n this.y = y;\n | raghu6306766 | NORMAL | 2021-11-05T10:22:24.787710+00:00 | 2021-11-05T10:22:24.787742+00:00 | 852 | false | class Solution {\n \n\tpublic class Coordinate{\n int x , y;\n Coordinate(int x , int y){\n this.x = x;\n this.y = y;\n }\n }\n \n public boolean isValidCoordinate(int x , int y , List<List<Boolean>> visited){\n return x < visited.size() && y < visited.get(x... | 6 | 0 | ['Breadth-First Search', 'Java'] | 0 |
diagonal-traverse-ii | 【Video】BFS & Queue | video-bfs-queue-by-niits-djan | Intuition\nUsing BFS\n\n---\n\n# Solution Video\n\nhttps://youtu.be/4wkt4kGip64\n\n\u25A0 Timeline of the video\n0:04 How we think about a solution\n1:08 How ca | niits | NORMAL | 2024-04-25T00:39:19.107536+00:00 | 2024-04-25T00:39:19.107557+00:00 | 107 | false | # Intuition\nUsing BFS\n\n---\n\n# Solution Video\n\nhttps://youtu.be/4wkt4kGip64\n\n\u25A0 Timeline of the video\n`0:04` How we think about a solution\n`1:08` How can you put numbers into queue with right order?\n`2:34` Demonstrate how it works\n`6:24` Summary of main idea\n`6:47` Coding\n`8:40` Time Complexity and Sp... | 5 | 0 | ['C++', 'Java', 'Python3', 'JavaScript'] | 0 |
diagonal-traverse-ii | 👨🎤🤕👨🦽Beats 100% 🤜 VS 🤛 Clean Code 🧹🧼🛀 | beats-100-vs-clean-code-by-navid-7aka | \n\n\n\n\n# Why does this beat 100% (or sometimes 99% depending on LeetCode Mode)?\n\nWe don\'t waste any time more than necessary and use the proper data struc | navid | NORMAL | 2023-11-22T09:28:00.916130+00:00 | 2023-11-22T09:29:02.792013+00:00 | 319 | false | \n\n\n\n\n# Why does this beat 100% (or sometimes 99% depending on LeetCode Mode)?\n\nWe don\'t waste any time more than necessary and use the proper data structure\n\n# Can you be more concrete t... | 5 | 0 | ['Java'] | 0 |
diagonal-traverse-ii | C++/Python, bucket solution with explanation | cpython-bucket-solution-with-explanation-p6xf | bucket\n\nFor each diagonal line, sum of each coordinate on the same line are the same.\nSo, create m + n - 1 buckets, where m is number of row, n is max length | shun6096tw | NORMAL | 2023-11-22T05:57:30.589954+00:00 | 2023-11-24T00:40:12.889767+00:00 | 183 | false | ### bucket\n\nFor each diagonal line, sum of each coordinate on the same line are the same.\nSo, create m + n - 1 buckets, where m is number of row, n is max length of a column,\nwhen we traverse array, put an ... | 5 | 0 | ['C', 'Python'] | 0 |
diagonal-traverse-ii | Java One-Liner Using Streams API (Unreadable) | java-one-liner-using-streams-api-unreada-8p3o | Intro\nWe are going to assume that you have seen the other solutions. This was my initial solution.\n\nclass Solution {\n public int[] findDiagonalOrder(List | ayazmost | NORMAL | 2023-11-22T05:09:31.342610+00:00 | 2023-11-22T05:11:56.958039+00:00 | 438 | false | # Intro\nWe are going to assume that you have seen the other solutions. This was my initial solution.\n```\nclass Solution {\n public int[] findDiagonalOrder(List<List<Integer>> nums) {\n ArrayList<int[]> list = new ArrayList<>();\n for (int i = 0; i < nums.size(); i++) {\n for (int j = 0; j... | 5 | 0 | ['Java'] | 3 |
diagonal-traverse-ii | Kotlin List of Diagonals, O(n) Runtime and Space | kotlin-list-of-diagonals-on-runtime-and-448o5 | Intuition\nIterating through the existing list in diagonal fashion isn\'t that difficult, but since it is not uniform width, there are large gaps that will have | jschnall | NORMAL | 2023-11-22T02:50:11.549885+00:00 | 2023-11-22T03:10:26.680079+00:00 | 68 | false | # Intuition\nIterating through the existing list in diagonal fashion isn\'t that difficult, but since it is not uniform width, there are large gaps that will have to be traversed, which is inefficient. This could be mitigated somewhat by finding the row(s) with the maxWidth to break out of loops earlier, but it seemed ... | 5 | 0 | ['Kotlin'] | 0 |
diagonal-traverse-ii | 🌊Enhanced Diagonal Traversal of 2D Arrays: Handling, Directional Options, and Space Optimization⚡️ | enhanced-diagonal-traversal-of-2d-arrays-4fbe | Intuition\nGiven a 2D array, to traverse it in diagonal order means moving along the diagonals, starting from the top-left corner, going down to the bottom-righ | deleted_user | NORMAL | 2023-11-22T02:00:41.886719+00:00 | 2023-11-22T02:00:41.886740+00:00 | 373 | false | # Intuition\nGiven a 2D array, to traverse it in diagonal order means moving along the diagonals, starting from the top-left corner, going down to the bottom-right corner, and covering elements in a zigzag pattern.\n\n# Approach\n1. Diagonal Mapping: Create a mapping where each diagonal has its list of elements. To ide... | 5 | 0 | ['Python'] | 1 |
diagonal-traverse-ii | [C++] || Sum of indices is same for all diagonal elements | c-sum-of-indices-is-same-for-all-diagona-lbav | For each sum of indices i + j store their corresponding elements in a map.\n\n* Traverse the map from least sum to max sum and print elements in reverse manner. | rahul921 | NORMAL | 2022-08-11T05:28:10.083698+00:00 | 2022-08-11T05:28:52.941037+00:00 | 773 | false | * For each sum of indices `i + j` store their corresponding elements in a map.\n\n* Traverse the map from least sum to max sum and print elements in reverse manner.\n```\nclass Solution {\npublic:\n unordered_map<int,vector<int>> mpp ;\n vector<int> findDiagonalOrder(vector<vector<int>>& nums) {\n int c = ... | 5 | 0 | ['C'] | 0 |
diagonal-traverse-ii | Java | Picture included | One pass | Easy Hashmap Solution | java-picture-included-one-pass-easy-hash-yche | \n\nclass Solution {\n public int[] findDiagonalOrder(List<List<Integer>> nums) {\n if(nums==null || nums.size()==0) return null;\n \n H | U99Omega | NORMAL | 2021-04-26T18:37:20.451244+00:00 | 2021-04-26T18:37:20.451277+00:00 | 336 | false | \n```\nclass Solution {\n public int[] findDiagonalOrder(List<List<Integer>> nums) {\n if(nums==null || nums.size()==0) return null;\n \n HashMap<Integer,ArrayList<Integer>> map=new Hash... | 5 | 1 | ['Java'] | 0 |
diagonal-traverse-ii | Think of the grid as a binary tree, then do a row traversal | think-of-the-grid-as-a-binary-tree-then-wuwgu | Think of the grid as a binary tree. The square at (0, 0) is the root.\n\nUsing the example from the description, let\'s visualise a few nodes. \nThe number 1 is | timothyleong97 | NORMAL | 2020-12-25T10:29:16.028796+00:00 | 2020-12-25T14:08:57.304306+00:00 | 461 | false | Think of the grid as a binary tree. The square at `(0, 0)` is the root.\n\nUsing the example from the description, let\'s visualise a few nodes. \nThe number `1` is the root of the tree.\n`6` and `2` are it\'s ... | 5 | 0 | ['Binary Tree'] | 0 |
diagonal-traverse-ii | Py3 Sol: beats 78%, 1 Pass Sol, Easy to understand | py3-sol-beats-78-1-pass-sol-easy-to-unde-ma4l | Concept: Along diagonal, the sum of the indices are always SAME. For ex- take index- [0,2], [1,1], [2,0] (all have a total sum of 2).\nSo we will try to make a | ycverma005 | NORMAL | 2020-04-30T16:31:13.173432+00:00 | 2020-05-02T17:53:45.759863+00:00 | 820 | false | Concept: Along diagonal, the sum of the indices are always SAME. For ex- take index- [0,2], [1,1], [2,0] (all have a total sum of 2).\nSo we will try to make a empty List of list, and `sum of index` will act a `new index` for `List of list`. \n\n```\nclass Solution:\n def findDiagonalOrder(self, nums: List[List[int]... | 5 | 1 | ['Python', 'Python3'] | 4 |
diagonal-traverse-ii | EEzz simple Python solution using Hashmap/deafulatdict(list)! | eezz-simple-python-solution-using-hashma-3hni | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n(i+j) for same\xA0diago | yashaswisingh47 | NORMAL | 2023-11-22T13:41:26.873444+00:00 | 2023-11-22T13:41:26.873467+00:00 | 367 | 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(i+j) for same\xA0diagonal elements is equal. \nThey will be added to a result(res) list after being stored in a hashmap. (To obtain the upward diagonal traversal, rev... | 4 | 0 | ['Hash Table', 'Sorting', 'Matrix', 'Python3'] | 0 |
diagonal-traverse-ii | ✅ Easy and small solution 🔥 simple idea 🚀 with some optimization | easy-and-small-solution-simple-idea-with-kk9z | Intuition\n- convert the photo to sum indexes it will be pattern problem, if we see he but all indexes with (i+j)=0 first then but all indexes with sum (i+j)=1 | omar_walied_ismail | NORMAL | 2023-11-22T05:21:53.509561+00:00 | 2023-11-22T05:21:53.509588+00:00 | 361 | false | # Intuition\n- convert the photo to sum indexes it will be pattern problem, if we see he but all indexes with `(i+j)=0` first then but all indexes with sum `(i+j)=1` and so on, but he put it in `reversed order` so I need to store every sum in vector and reverse it and put it in `ans`\n\n# Approach\n1. create array of v... | 4 | 0 | ['Array', 'C++'] | 2 |
diagonal-traverse-ii | C# Solution for Diagonal Traverse II Problem | c-solution-for-diagonal-traverse-ii-prob-7kyv | Intuition\n Describe your first thoughts on how to solve this problem. \n1.\tGrouping by Diagonal Sum: The solution aims to group elements from the input 2D lis | Aman_Raj_Sinha | NORMAL | 2023-11-22T03:15:15.959627+00:00 | 2023-11-22T03:16:47.758909+00:00 | 256 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n1.\tGrouping by Diagonal Sum: The solution aims to group elements from the input 2D list based on the sum of their row and column indices, simulating diagonal traversal.\n2.\tRetrieving Elements in Order: After creating these groups, it r... | 4 | 1 | ['C#'] | 1 |
diagonal-traverse-ii | Rust: queue | rust-queue-by-natekot-34jy | \nuse std::collections::VecDeque;\n \nimpl Solution {\n pub fn find_diagonal_order(nums: Vec<Vec<i32>>) -> Vec<i32> {\n \n let n = nums.len();\n let | natekot | NORMAL | 2023-11-22T01:45:26.130133+00:00 | 2023-11-22T01:45:26.130156+00:00 | 71 | false | ```\nuse std::collections::VecDeque;\n \nimpl Solution {\n pub fn find_diagonal_order(nums: Vec<Vec<i32>>) -> Vec<i32> {\n \n let n = nums.len();\n let mut q = VecDeque::new();\n let mut ans = vec![];\n \n q.push_back((0, 0));\n \n while let Some((i, j)) = q.pop_front() {\n \n ans.push(nums[... | 4 | 0 | ['Rust'] | 1 |
diagonal-traverse-ii | [Java] Clean Code without HashMap | java-clean-code-without-hashmap-by-xiang-1tu0 | \nclass Solution {\n public int[] findDiagonalOrder(List<List<Integer>> nums) {\n int m = nums.size(), maxSum = 0, size = 0, index = 0;\n List< | xiangcan | NORMAL | 2023-06-19T17:44:13.552165+00:00 | 2023-06-19T17:44:13.552188+00:00 | 470 | false | ```\nclass Solution {\n public int[] findDiagonalOrder(List<List<Integer>> nums) {\n int m = nums.size(), maxSum = 0, size = 0, index = 0;\n List<Integer>[] map = new ArrayList[100001];\n for (int i = 0; i < m; i++) {\n size += nums.get(i).size();\n for (int j = 0; j < nums... | 4 | 0 | ['Java'] | 1 |
diagonal-traverse-ii | C++|| Super Easy Solution || Diagonal Traverse II | c-super-easy-solution-diagonal-traverse-4wkw3 | \'\'\'\nSuper Easy Solution using map\nclass Solution {\npublic:\n\n\t vector findDiagonalOrder(vector>& nums) {\n map> mp;\n | code_with_dua | NORMAL | 2022-07-05T07:30:29.835150+00:00 | 2022-07-05T07:30:29.835193+00:00 | 387 | false | \'\'\'\n**Super Easy Solution using map**\nclass Solution {\npublic:\n\n\t vector<int> findDiagonalOrder(vector<vector<int>>& nums) {\n map<int,vector<int>> mp;\n //[i+j],{vector}\n for(int i=0;i<nums.size();i++) //0->{1}\n {... | 4 | 0 | ['C'] | 1 |
diagonal-traverse-ii | Python Heap Solution | python-heap-solution-by-xxixos-jkr8 | We are aware that the sum of row index and col index of each element in a diagonal is the same. \n\nWe can use this property to utilize minHeap, so that element | xxixos | NORMAL | 2022-01-21T14:47:34.309604+00:00 | 2022-01-21T14:48:22.789992+00:00 | 98 | false | We are aware that the sum of row index and col index of each element in a diagonal is the same. \n\nWe can use this property to utilize minHeap, so that element with smaller sum comes out first, and if the sums are the same, element with smaller col index comes first.\n\n```\nclass Solution:\n def findDiagonalOrder(... | 4 | 0 | ['Heap (Priority Queue)'] | 2 |
diagonal-traverse-ii | [Java] Easy to Understand 22 ms 93.27% | java-easy-to-understand-22-ms-9327-by-hd-9bcd | \nclass Solution {\n class Point {\n int row;\n int sum;\n int val;\n Point(int row,int sum,int val) {\n this.row = ro | hdobhal | NORMAL | 2020-09-11T11:59:34.418972+00:00 | 2020-09-11T11:59:34.419015+00:00 | 691 | false | ```\nclass Solution {\n class Point {\n int row;\n int sum;\n int val;\n Point(int row,int sum,int val) {\n this.row = row;\n this.sum = sum;\n this.val = val;\n }\n \n }\n public int[] findDiagonalOrder(List<List<Integer>> nums) {\n ... | 4 | 1 | ['Java'] | 1 |
diagonal-traverse-ii | [C++]O(N) Clean Code without map | con-clean-code-without-map-by-jiah-wsji | cpp\nclass Solution {\npublic:\n vector<int> findDiagonalOrder(vector<vector<int>>& nums) {\n vector<list<int>> data;\n for (int i = 0; i < num | jiah | NORMAL | 2020-04-26T04:49:43.256133+00:00 | 2020-04-26T04:49:43.256185+00:00 | 313 | false | ```cpp\nclass Solution {\npublic:\n vector<int> findDiagonalOrder(vector<vector<int>>& nums) {\n vector<list<int>> data;\n for (int i = 0; i < nums.size(); i++) {\n for (int j = 0; j < nums[i].size(); j++) {\n if (i+j == data.size()) \n data.push_back(list<i... | 4 | 1 | [] | 1 |
diagonal-traverse-ii | C++|easiest|map|explaination | ceasiestmapexplaination-by-alex3898-vn8a | do numbering of the elements and push them into map \nthen traverse the map\n\nclass Solution \n{\n \npublic:\n vector<int> findDiagonalOrder(vector<vecto | alex3898 | NORMAL | 2020-04-26T04:02:32.697449+00:00 | 2020-04-26T04:02:32.697486+00:00 | 450 | false | do numbering of the elements and push them into map \nthen traverse the map\n```\nclass Solution \n{\n \npublic:\n vector<int> findDiagonalOrder(vector<vector<int>>& nums) \n {\n int m=nums.size(),n=nums[0].size();\n \n int numbering=1;\n map<int,vector<int>>mp;\n for(int i=0;i... | 4 | 1 | ['C'] | 3 |
diagonal-traverse-ii | Short and Simple C++, solution with explanation | short-and-simple-c-solution-with-explana-4ln5 | Main idea: to identify similar blocks--> for this add their ith and jth (row or col) respectively. \nnums(1,0) and nums(0,1) will be in same map with key = (1+0 | prateekchhikara | NORMAL | 2020-04-26T04:01:50.993358+00:00 | 2020-04-26T05:43:44.370418+00:00 | 483 | false | ***Main idea:*** to identify similar blocks--> for this add their ith and jth (row or col) respectively. \nnums(1,0) and nums(0,1) will be in same map with key = (1+0 = 0+1) \n\n```\nvector<int> findDiagonalOrder(vector<vector<int>>& nums) \n {\n unordered_map<int, vector<int>> mp;\n int n = nums.size(... | 4 | 1 | [] | 3 |
diagonal-traverse-ii | EASY Solution Using Hash Map | easy-solution-using-hash-map-by-danil_m-fza1 | **Explanation and Algorithm Problem Breakdown **The problem asks us to traverse a list of lists (a 2D structure) in a diagonal order and return the elements in | Danil_M | NORMAL | 2025-02-20T08:34:12.656546+00:00 | 2025-02-20T08:34:12.656546+00:00 | 66 | false | # **Explanation and Algorithm Problem Breakdown **
The problem asks us to traverse a list of lists (a 2D structure) in a diagonal order and return the elements in that order as an array. The diagonals are defined by the sum of the row and column indices.
**Algorithm
Diagonal Grouping:**
Create a map (a MutableMap) ... | 3 | 0 | ['Hash Table', 'Kotlin'] | 0 |
diagonal-traverse-ii | Simple Approach ✔ with Best explanation ❤ C++ 🤞 Comments Added 😍 | simple-approach-with-best-explanation-c-jom40 | Intuition and approach :\n AFTER little bit of analyzing, you will surely find the patter.. that is :\n1st we have to get/find all diagonal pairs..and we can | DEvilBackInGame | NORMAL | 2023-11-22T17:19:43.127561+00:00 | 2023-11-22T17:21:37.949354+00:00 | 33 | false | # Intuition and approach :\n AFTER little bit of analyzing, you will surely find the patter.. that is :\n1st we have to get/find all diagonal pairs..and we can get that as follow:\n\n1. create a 2d array/vector to store all same diagonal pairs .\n2. then start inserting the element of ith row to all row starting from... | 3 | 0 | ['C++'] | 0 |
diagonal-traverse-ii | easy solution | easy-solution-by-skr0489-qczn | Intuition\nThe sum of i index and j index of diagonal element is same\nso , we use map to store the diagonal element wrt the some of index\n Describe your first | skr0489 | NORMAL | 2023-11-22T13:10:46.711622+00:00 | 2023-11-22T13:10:46.711639+00:00 | 9 | false | # Intuition\nThe sum of i index and j index of diagonal element is same\nso , we use map to store the diagonal element wrt the some of index\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... | 3 | 0 | ['Ordered Map', 'C++'] | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.