title
stringlengths
1
100
titleSlug
stringlengths
3
77
Java
int64
0
1
Python3
int64
1
1
content
stringlengths
28
44.4k
voteCount
int64
0
3.67k
question_content
stringlengths
65
5k
question_hints
stringclasses
970 values
Python3
two-sum-ii-input-array-is-sorted
0
1
\nO(n)\n# Code\n```\nclass Solution:\n def twoSum(self, numbers: List[int], target: int) -> List[int]:\n left, right = 0, len(numbers) - 1 # Initialize two pointers, left and right, pointing to the start and end of the list respectively.\n\n while left < right: # Continue the loop until the pointers ...
4
Given a **1-indexed** array of integers `numbers` that is already **_sorted in non-decreasing order_**, find two numbers such that they add up to a specific `target` number. Let these two numbers be `numbers[index1]` and `numbers[index2]` where `1 <= index1 < index2 <= numbers.length`. Return _the indices of the two n...
null
clean Python3 code using two pointers technique
two-sum-ii-input-array-is-sorted
0
1
# Code\n```\nclass Solution:\n def twoSum(self, numbers: List[int], target: int) -> List[int]:\n l,r=0,len(numbers)-1\n while(l<r):\n sum=numbers[l]+numbers[r]\n if(sum==target):return [l+1,r+1]\n elif sum>target:r-=1\n else:l+=1\n```
3
Given a **1-indexed** array of integers `numbers` that is already **_sorted in non-decreasing order_**, find two numbers such that they add up to a specific `target` number. Let these two numbers be `numbers[index1]` and `numbers[index2]` where `1 <= index1 < index2 <= numbers.length`. Return _the indices of the two n...
null
UNIQUE TWO POINTER SOLUTION | Visual Explanation
two-sum-ii-input-array-is-sorted
0
1
\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nCreate two pointers where one points at the first index in the array and the other points at the second index. \n![image.png](https://assets.leetcode.com/users/images/d1bf7a1b-14d2-4c20-95fb-f0e28e8ef04c_1692158325.868738.png)\n\nIf the sum of the...
7
Given a **1-indexed** array of integers `numbers` that is already **_sorted in non-decreasing order_**, find two numbers such that they add up to a specific `target` number. Let these two numbers be `numbers[index1]` and `numbers[index2]` where `1 <= index1 < index2 <= numbers.length`. Return _the indices of the two n...
null
167. Two pointer technique | no nested loops
two-sum-ii-input-array-is-sorted
0
1
# Code\n```\nclass Solution:\n def twoSum(self, numbers: List[int], target: int) -> List[int]:\n left, right = 0, len(numbers)-1\n while left < right:\n tot = numbers[left] + numbers[right]\n if tot< target: \n left += 1\n elif tot > target:\n ...
1
Given a **1-indexed** array of integers `numbers` that is already **_sorted in non-decreasing order_**, find two numbers such that they add up to a specific `target` number. Let these two numbers be `numbers[index1]` and `numbers[index2]` where `1 <= index1 < index2 <= numbers.length`. Return _the indices of the two n...
null
Easy and Detailed solution with 8 lines of Python Code
two-sum-ii-input-array-is-sorted
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFirst of all I have written down the problem description in a simpler way, then I thought about having two pointers, one at the begining of the list, and the other pointing at the last element in the list, then we should repeat the proces...
3
Given a **1-indexed** array of integers `numbers` that is already **_sorted in non-decreasing order_**, find two numbers such that they add up to a specific `target` number. Let these two numbers be `numbers[index1]` and `numbers[index2]` where `1 <= index1 < index2 <= numbers.length`. Return _the indices of the two n...
null
✅ 100% Recursive & Iterative 2-Approaches
excel-sheet-column-title
1
1
# Problem Understanding\n\nIn the "Excel Sheet Column Title" problem, we are given an integer representing a column number. The task is to return its corresponding column title as it appears in an Excel sheet, where the letters range from A to Z for the numbers 1 to 26, and then AA to AZ, BA to BZ, and so on.\n\nFor in...
56
Given an integer `columnNumber`, return _its corresponding column title as it appears in an Excel sheet_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnNumber = 1 **Output:** "A " **Example 2:** **Input:** columnNumber = 28 **Output:** "AB " **Example 3:**...
null
Easy || 0 ms || 100% || Fully Explained (Java, C++, Python, Python3)
excel-sheet-column-title
1
1
# **Java Solution:**\nRuntime: 0 ms, faster than 100.00% of Java online submissions for Excel Sheet Column Title.\n```\nclass Solution {\n public String convertToTitle(int columnNumber) {\n // Create an empty string for storing the characters...\n StringBuilder output = new StringBuilder();\n //...
90
Given an integer `columnNumber`, return _its corresponding column title as it appears in an Excel sheet_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnNumber = 1 **Output:** "A " **Example 2:** **Input:** columnNumber = 28 **Output:** "AB " **Example 3:**...
null
Simplest Python solution. Divide by 26
excel-sheet-column-title
0
1
\n\n# Code\n```\nclass Solution:\n def convertToTitle(self, n: int) -> str:\n res = ""\n while n > 0:\n r = (n-1) % 26\n n = (n-1)// 26\n res += chr(ord("A")+r)\n return res[::-1]\n```
4
Given an integer `columnNumber`, return _its corresponding column title as it appears in an Excel sheet_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnNumber = 1 **Output:** "A " **Example 2:** **Input:** columnNumber = 28 **Output:** "AB " **Example 3:**...
null
【Video】Ex-Amazon explains a solution with Python, JavaScript, Java and C++
excel-sheet-column-title
1
1
# Intuition\nConvert to base 26 system.\n\n# Solution Video\n\n### Please subscribe to my channel from here. I have 246 videos as of August 22nd.\n\nhttp://www.youtube.com/channel/UC9RMNwYTL3SXCP6ShLWVFww?sub_confirmation=1\n\nhttps://youtu.be/q8DkXSns3Xk\n\n---\n\n# Approach\nThis is based on Python. Other might be di...
9
Given an integer `columnNumber`, return _its corresponding column title as it appears in an Excel sheet_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnNumber = 1 **Output:** "A " **Example 2:** **Input:** columnNumber = 28 **Output:** "AB " **Example 3:**...
null
Python 3 || 6 lines, rotated string || T/M: 100% / 100%
excel-sheet-column-title
0
1
```\nclass Solution:\n def convertToTitle(self, n: int) -> str:\n\n alpha, ans = \'Z\'+ ascii_uppercase, ""\n\n while n:\n n, r = divmod(n,26)\n ans = alpha[r] + ans\n if not r: n-= 1\n return ans\n```\n[https://leetcode.com/problems/excel-sheet-column-title/subm...
5
Given an integer `columnNumber`, return _its corresponding column title as it appears in an Excel sheet_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnNumber = 1 **Output:** "A " **Example 2:** **Input:** columnNumber = 28 **Output:** "AB " **Example 3:**...
null
Python easy solution.
excel-sheet-column-title
0
1
# 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
Given an integer `columnNumber`, return _its corresponding column title as it appears in an Excel sheet_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnNumber = 1 **Output:** "A " **Example 2:** **Input:** columnNumber = 28 **Output:** "AB " **Example 3:**...
null
Converting Column Number to Column Title in Excel Sheet using Base-26 System
excel-sheet-column-title
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem requires us to convert a given column number into the corresponding column title in an Excel sheet. We can use the ASCII codes of the capital letters to represent the column titles.\n# Approach\n<!-- Describe your approach to ...
3
Given an integer `columnNumber`, return _its corresponding column title as it appears in an Excel sheet_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnNumber = 1 **Output:** "A " **Example 2:** **Input:** columnNumber = 28 **Output:** "AB " **Example 3:**...
null
Python3 Solution
excel-sheet-column-title
0
1
\n```\nclass Solution:\n def convertToTitle(self, columnNumber: int) -> str: \n ans="" \n while columnNumber>0:\n c=chr(ord(\'A\')+(columnNumber-1)%26)\n ans=c+ans\n columnNumber=(columnNumber-1)//26 \n return ans \n```
7
Given an integer `columnNumber`, return _its corresponding column title as it appears in an Excel sheet_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnNumber = 1 **Output:** "A " **Example 2:** **Input:** columnNumber = 28 **Output:** "AB " **Example 3:**...
null
Easy.py
excel-sheet-column-title
0
1
# Code\n```\nclass Solution:\n def convertToTitle(self, n: int) -> str:\n if n<27:\n return chr(ord(\'A\')+(n-1)%26)\n ans=""\n while n>0:\n if n%26==0:\n ans+=chr(ord(\'A\')+25)\n n-=1\n else:\n ans+=chr(ord(\'A\')+n%...
2
Given an integer `columnNumber`, return _its corresponding column title as it appears in an Excel sheet_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnNumber = 1 **Output:** "A " **Example 2:** **Input:** columnNumber = 28 **Output:** "AB " **Example 3:**...
null
Excel Sheet Column Title in Python
excel-sheet-column-title
0
1
# Intuition\nAssign characters as per unicode values, keeping in mind the values that go beyond the 26 letters of the alphabet.\n\n# Approach\nAssign the value of `columnNumber` to a variable `n`. Initialize a blank string `res`. Initialize a while loop with the condition `n > 0`. \nInside the `while loop`:\nDecrement ...
3
Given an integer `columnNumber`, return _its corresponding column title as it appears in an Excel sheet_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnNumber = 1 **Output:** "A " **Example 2:** **Input:** columnNumber = 28 **Output:** "AB " **Example 3:**...
null
Python Easy Solution
excel-sheet-column-title
0
1
# Code\n```\nclass Solution:\n def convertToTitle(self, columnNumber: int) -> str:\n res=""\n while(columnNumber>0):\n columnNumber-=1\n i=columnNumber%26\n res+=chr(65+i)\n columnNumber=columnNumber//26\n return res[::-1]\n```\n\n***Please Upvote***
3
Given an integer `columnNumber`, return _its corresponding column title as it appears in an Excel sheet_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnNumber = 1 **Output:** "A " **Example 2:** **Input:** columnNumber = 28 **Output:** "AB " **Example 3:**...
null
Python | Fastest | Easy to Understand | Optimal Solution
excel-sheet-column-title
0
1
# Python | Fastest | Easy to Understand | Optimal Solution\n```\nclass Solution:\n def convertToTitle(self, n: int) -> str:\n ans = []\n while(n > 0):\n n -= 1\n curr = n % 26\n n = int(n / 26)\n ans.append(chr(curr + ord(\'A\')))\n \n return \'...
5
Given an integer `columnNumber`, return _its corresponding column title as it appears in an Excel sheet_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnNumber = 1 **Output:** "A " **Example 2:** **Input:** columnNumber = 28 **Output:** "AB " **Example 3:**...
null
Simple 3 lines code, beats 100% || C++ || Java || Python
excel-sheet-column-title
1
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nJust take out the last element from columnNumber smaller than or equal to 26 (%26) and put the equivalent character from capital letters in the string and reduce the c...
2
Given an integer `columnNumber`, return _its corresponding column title as it appears in an Excel sheet_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnNumber = 1 **Output:** "A " **Example 2:** **Input:** columnNumber = 28 **Output:** "AB " **Example 3:**...
null
Python Easy to Understand Solution
excel-sheet-column-title
0
1
Please upvote if you like it.\n```\nclass Solution:\n def convertToTitle(self, num: int) -> str:\n ans=""\n while num > 0:\n num -= 1\n ans = chr(num % 26 + 65) + ans\n num //= 26\n return ans
6
Given an integer `columnNumber`, return _its corresponding column title as it appears in an Excel sheet_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnNumber = 1 **Output:** "A " **Example 2:** **Input:** columnNumber = 28 **Output:** "AB " **Example 3:**...
null
Excel sheet column Title using Python3
excel-sheet-column-title
0
1
# Code\n```\nclass Solution:\n def convertToTitle(self, columnNumber: int) -> str:\n s=\'\'\n while columnNumber > 0:\n d = (columnNumber - 1) % 26\n s += chr(d + ord(\'A\'))\n columnNumber = (columnNumber - 1) // 26\n return s[::-1] \n\n\n\n```
1
Given an integer `columnNumber`, return _its corresponding column title as it appears in an Excel sheet_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnNumber = 1 **Output:** "A " **Example 2:** **Input:** columnNumber = 28 **Output:** "AB " **Example 3:**...
null
✅3 Method's || Beats 100% || C++ || JAVA || PYTHON || Beginner Friendly🔥🔥🔥
majority-element
1
1
# Approach 1: Sorting\n\n# Intuition:\nThe intuition behind this approach is that if an element occurs more than n/2 times in the array (where n is the size of the array), it will always occupy the middle position when the array is sorted. Therefore, we can sort the array and return the element at index n/2.\n\n# Expla...
1,271
Given an array `nums` of size `n`, return _the majority element_. The majority element is the element that appears more than `⌊n / 2⌋` times. You may assume that the majority element always exists in the array. **Example 1:** **Input:** nums = \[3,2,3\] **Output:** 3 **Example 2:** **Input:** nums = \[2,2,1,1,1,2,...
null
Solution
majority-element
1
1
```C++ []\nclass Solution {\npublic:\n int majorityElement(vector<int>& nums) {\n \n int n = nums.size();\n int k = ceil(n/2);\n\n unordered_map<int,int>m1;\n for(int i=0;i<nums.size();i++){\n m1[nums[i]]++;\n }\n int g=0;\n for(auto it:m1){\n ...
204
Given an array `nums` of size `n`, return _the majority element_. The majority element is the element that appears more than `⌊n / 2⌋` times. You may assume that the majority element always exists in the array. **Example 1:** **Input:** nums = \[3,2,3\] **Output:** 3 **Example 2:** **Input:** nums = \[2,2,1,1,1,2,...
null
O( n*log(n) )✅ | Python (Step by step explanation)✅
majority-element
0
1
# Intuition\n<!-- Your intuition or thoughts about solving the problem -->\nMy intuition is to use Python\'s `statistics.mode` function to directly find the majority element in the list.\n\n# Approach\n<!-- Describe your approach to solving the problem -->\n1. Utilize the `statistics.mode` function, which returns the m...
2
Given an array `nums` of size `n`, return _the majority element_. The majority element is the element that appears more than `⌊n / 2⌋` times. You may assume that the majority element always exists in the array. **Example 1:** **Input:** nums = \[3,2,3\] **Output:** 3 **Example 2:** **Input:** nums = \[2,2,1,1,1,2,...
null
Python3: O(N) time, O(1) space; Boyer-Moore's majority voting algo with link to easy explanation
majority-element
0
1
# Intuition\nTo solve it in $O(N)$ time and $O(1)$ space, we canot use a hashmap ($O(N)$ space) or sort the array in-place ($O(NlogN)$ time). Therefore, we have to use Boyer-Moore\u2019s majority voting algorithm which does the trick.\n\n# Approach\nTo understand how the algorithm works, see [C++|| Moore\'s Voting Algo...
0
Given an array `nums` of size `n`, return _the majority element_. The majority element is the element that appears more than `⌊n / 2⌋` times. You may assume that the majority element always exists in the array. **Example 1:** **Input:** nums = \[3,2,3\] **Output:** 3 **Example 2:** **Input:** nums = \[2,2,1,1,1,2,...
null
Beats 85.08% of users with Python3
majority-element
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
Given an array `nums` of size `n`, return _the majority element_. The majority element is the element that appears more than `⌊n / 2⌋` times. You may assume that the majority element always exists in the array. **Example 1:** **Input:** nums = \[3,2,3\] **Output:** 3 **Example 2:** **Input:** nums = \[2,2,1,1,1,2,...
null
✔️ [Python3] CLEAN SOLUTION (๑❛ꆚ❛๑), Explained
excel-sheet-column-number
0
1
**UPVOTE if you like (\uD83C\uDF38\u25E0\u203F\u25E0), If you have any question, feel free to ask.**\n\nEssentially, what we asked to do here is to convert a number in the base 26 numeral system to a decimal number. This is a standard algorithm, where we iterate over the digits from right to left and multiply them by t...
160
Given a string `columnTitle` that represents the column title as appears in an Excel sheet, return _its corresponding column number_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnTitle = "A " **Output:** 1 **Example 2:** **Input:** columnTitle = "AB " **Ou...
null
[Python] | Simple & Clean code
excel-sheet-column-number
0
1
# Code\n```\nclass Solution:\n def titleToNumber(self, s: str) -> int:\n n = len(s)\n cnt = [0] * 7\n p = 0\n for i in range(n -1, -1, -1):\n cnt[i] = (ord(s[i]) - ord(\'A\') + 1) * 26 ** p\n p += 1\n return sum(cnt)\n```
2
Given a string `columnTitle` that represents the column title as appears in an Excel sheet, return _its corresponding column number_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnTitle = "A " **Output:** 1 **Example 2:** **Input:** columnTitle = "AB " **Ou...
null
Simple Question with best appoarch
excel-sheet-column-number
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
1
Given a string `columnTitle` that represents the column title as appears in an Excel sheet, return _its corresponding column number_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnTitle = "A " **Output:** 1 **Example 2:** **Input:** columnTitle = "AB " **Ou...
null
Beats : 7.07% [23/145 Top Interview Question]
excel-sheet-column-number
0
1
# Intuition\n*exponential value*\n\n# Approach\nThis code defines a class called `Solution` with a method called `titleToNumber` that takes a string `columnTitle` as input and returns an integer value that represents the column number corresponding to the given column title in an Excel spreadsheet.\n\nThe variables use...
1
Given a string `columnTitle` that represents the column title as appears in an Excel sheet, return _its corresponding column number_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnTitle = "A " **Output:** 1 **Example 2:** **Input:** columnTitle = "AB " **Ou...
null
Python 1 Line Solution
excel-sheet-column-number
0
1
# Code\n```\nclass Solution:\n def titleToNumber(self, columnTitle: str) -> int:\n cnt=0\n for i in range(len(columnTitle)):\n cnt+=(26**(len(columnTitle)-i-1))*(ord(columnTitle[i])-64)\n return cnt\n```\n\n***Please Upvote***
1
Given a string `columnTitle` that represents the column title as appears in an Excel sheet, return _its corresponding column number_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnTitle = "A " **Output:** 1 **Example 2:** **Input:** columnTitle = "AB " **Ou...
null
Simple Approach.
excel-sheet-column-number
0
1
# 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
Given a string `columnTitle` that represents the column title as appears in an Excel sheet, return _its corresponding column number_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnTitle = "A " **Output:** 1 **Example 2:** **Input:** columnTitle = "AB " **Ou...
null
Converting Excel column title to column number using positional value of letters.
excel-sheet-column-number
0
1
# Intuition\n To convert a column title to a corresponding column number in Excel, we need to understand the positional value of each letter in the title. Each letter in the title represents a value that is a power of 26, where the letter \'A\' represents the zeroth power of 26, \'B\' represents the first power of 26, ...
3
Given a string `columnTitle` that represents the column title as appears in an Excel sheet, return _its corresponding column number_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnTitle = "A " **Output:** 1 **Example 2:** **Input:** columnTitle = "AB " **Ou...
null
Python: the only explanation that is understandable and makes sense to those who just start
excel-sheet-column-number
0
1
**Disclaimer**: I hate when the "Discussion" session has tons of posts that contain just a few lines of code with indecipherable variables and an impossible-to-follow logic. For this question, I haven\'t found a single solution that a novice user can follow and understand. ```ord()``` is everywhere, etc. \n\n**Explana...
96
Given a string `columnTitle` that represents the column title as appears in an Excel sheet, return _its corresponding column number_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnTitle = "A " **Output:** 1 **Example 2:** **Input:** columnTitle = "AB " **Ou...
null
Easy || 100% || Explained || Java || C++|| Python (1 Line) || C || Python3
excel-sheet-column-number
1
1
**Problem Statement:**\nGiven a string columnTitle that represents the column title as appears in an Excel sheet, return its corresponding column number.\n**For example:**\n\n\t\t\t\t\t\tA -> 1\n\t\t\t\t\t\tB -> 2\n\t\t\t\t\t\tC -> 3\n\t\t\t\t\t\t............\n\t\t\t\t\t\tZ -> 26\n\t\t\t\t\t\tAA -> 27\n\t\t\t\t\t\tAB -...
15
Given a string `columnTitle` that represents the column title as appears in an Excel sheet, return _its corresponding column number_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnTitle = "A " **Output:** 1 **Example 2:** **Input:** columnTitle = "AB " **Ou...
null
Python Smallest Easiest Solution
excel-sheet-column-number
0
1
\n\n# Code\n```\nclass Solution(object):\n def titleToNumber(self, columnTitle):\n """\n :type columnTitle: str\n :rtype: int\n """\n s = 0\n for jj in columnTitle:\n s = s * 26 + ord(jj) - ord(\'A\') + 1\n return s\n\'\'\'Please Upvote\'\'\'\n```
4
Given a string `columnTitle` that represents the column title as appears in an Excel sheet, return _its corresponding column number_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnTitle = "A " **Output:** 1 **Example 2:** **Input:** columnTitle = "AB " **Ou...
null
✅ Python easy one liner | Explaination
excel-sheet-column-number
0
1
**How to form a number using a list of digits?**\n1. We take a variable ```ans``` and initialize it with 0 \n2. We traverse through the list and update the variable as ```ans = ans * 10 + currDigit ```\n\nIn this question we need to do the same but we multiply it with 26 instead of 10\n```ans = ans * 26 + currDigit```\...
20
Given a string `columnTitle` that represents the column title as appears in an Excel sheet, return _its corresponding column number_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnTitle = "A " **Output:** 1 **Example 2:** **Input:** columnTitle = "AB " **Ou...
null
best python solution beaten 98% codes in TC
excel-sheet-column-number
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nI have iterated the given input string from the end and multiplied the index of the character with 26 power of k value , which is intialized to zero.\nk=indicates the ...
5
Given a string `columnTitle` that represents the column title as appears in an Excel sheet, return _its corresponding column number_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnTitle = "A " **Output:** 1 **Example 2:** **Input:** columnTitle = "AB " **Ou...
null
best approach
excel-sheet-column-number
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
1
Given a string `columnTitle` that represents the column title as appears in an Excel sheet, return _its corresponding column number_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnTitle = "A " **Output:** 1 **Example 2:** **Input:** columnTitle = "AB " **Ou...
null
171: Solution with step by step explanation
excel-sheet-column-number
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nWe are given a string columnTitle representing the column title as appears in an Excel sheet. We are supposed to return its corresponding column number.\n\nOne way to solve the problem is by traversing the string columnTitle...
7
Given a string `columnTitle` that represents the column title as appears in an Excel sheet, return _its corresponding column number_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnTitle = "A " **Output:** 1 **Example 2:** **Input:** columnTitle = "AB " **Ou...
null
Python 3 : Super Easy To Understand With Explanation
excel-sheet-column-number
0
1
```\nclass Solution:\n def titleToNumber(self, columnTitle: str) -> int:\n \n p = 1\n summ = 0\n for i in columnTitle[::-1] :\n summ += p*(ord(i)-64) # -ord(A)+1\n p*= 26\n \n return summ\n \n```\n* \'\'\'\n\t\tA.....to......Z = 26 e...
13
Given a string `columnTitle` that represents the column title as appears in an Excel sheet, return _its corresponding column number_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnTitle = "A " **Output:** 1 **Example 2:** **Input:** columnTitle = "AB " **Ou...
null
DUMBEST WAY TO SOLVE THE PROBLEM :) !!!
excel-sheet-column-number
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
1
Given a string `columnTitle` that represents the column title as appears in an Excel sheet, return _its corresponding column number_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnTitle = "A " **Output:** 1 **Example 2:** **Input:** columnTitle = "AB " **Ou...
null
[Python] Intuitive Straightforward Beginner-friendly Mathematical Solution Using Dictionary
excel-sheet-column-number
0
1
## Step 1:\nTo start, when seeing the 26 English alphabets are used to represent numbers, the first intuition is to use a dictionary to pair 1-26 and A-Z, before considering the calculation in detials.\n* Method 1: \nUsing zip()\n```\nalphabet = \'ABCDEFGHIJKLMNOPQRSTUVWXYZ\'\nnums = range(1,27)\nalpha_dict = dict(zip(...
7
Given a string `columnTitle` that represents the column title as appears in an Excel sheet, return _its corresponding column number_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnTitle = "A " **Output:** 1 **Example 2:** **Input:** columnTitle = "AB " **Ou...
null
Easy to understand Python solution || Runtime: 27ms Faster than 96% of other solution
excel-sheet-column-number
0
1
Please Upvote if you like the solution.\n```\nclass Solution:\n def titleToNumber(self, columnTitle: str) -> int:\n a = 0\n for i in columnTitle:\n a = a * 26 + ord(i) - ord(\'A\') + 1\n return a
4
Given a string `columnTitle` that represents the column title as appears in an Excel sheet, return _its corresponding column number_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnTitle = "A " **Output:** 1 **Example 2:** **Input:** columnTitle = "AB " **Ou...
null
Short and Simple Python solution
excel-sheet-column-number
0
1
# Intuition\nEach character is mapped to its positional value in the alphabet, and the title\'s characters are iterated through to calculate the numeric representation.\n# Approach\nIterate through each character in the column title, calculate its positional value using the formula 26^(n-i-1) * (ASCII_value - 64), and ...
0
Given a string `columnTitle` that represents the column title as appears in an Excel sheet, return _its corresponding column number_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnTitle = "A " **Output:** 1 **Example 2:** **Input:** columnTitle = "AB " **Ou...
null
Python 3 Solution | O(n)
excel-sheet-column-number
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $...
1
Given a string `columnTitle` that represents the column title as appears in an Excel sheet, return _its corresponding column number_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnTitle = "A " **Output:** 1 **Example 2:** **Input:** columnTitle = "AB " **Ou...
null
Very Easy O(log₅n) Solution 0ms Beats 100%| Explanation
factorial-trailing-zeroes
0
1
![Screenshot (200).png](https://assets.leetcode.com/users/images/5b693b7d-fb02-4d04-b2e3-cb934ad8228e_1699899552.410264.png)\n\n# Intuition\nTo determine the number of trailing zeros in 152 factorial (152!), it\'s essential to understand that trailing zeros result from the multiplication of multiples of 5 and 2. The ke...
8
Given an integer `n`, return _the number of trailing zeroes in_ `n!`. Note that `n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1`. **Example 1:** **Input:** n = 3 **Output:** 0 **Explanation:** 3! = 6, no trailing zero. **Example 2:** **Input:** n = 5 **Output:** 1 **Explanation:** 5! = 120, one trailing zero. **Exa...
null
python simplest solution✅✅
factorial-trailing-zeroes
0
1
\n\n\n\n# Time complexity:\nThe time complexity of this approach is O(log n) because the while loop runs until \'5^a\' is less than or equal to \'n\'. As we multiply \'b\' by 5 in each iteration, the loop will run approximately log base 5 of \'n\' times.\n\n# Space complexity:\nThe space complexity of this approach is ...
6
Given an integer `n`, return _the number of trailing zeroes in_ `n!`. Note that `n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1`. **Example 1:** **Input:** n = 3 **Output:** 0 **Explanation:** 3! = 6, no trailing zero. **Example 2:** **Input:** n = 5 **Output:** 1 **Explanation:** 5! = 120, one trailing zero. **Exa...
null
172. Factorial Trailing Zeroes | Python3 Solution | Brute Force Approach
factorial-trailing-zeroes
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSimply Apply Brute Force Method\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. First find factorial of a number.\n2. converted into string.\n3. converted into list and reverse it list.\n4. Find the frequency of...
1
Given an integer `n`, return _the number of trailing zeroes in_ `n!`. Note that `n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1`. **Example 1:** **Input:** n = 3 **Output:** 0 **Explanation:** 3! = 6, no trailing zero. **Example 2:** **Input:** n = 5 **Output:** 1 **Explanation:** 5! = 120, one trailing zero. **Exa...
null
Python Log(n) Loop | 100% Speed
factorial-trailing-zeroes
0
1
**Python Log(n) Loop | 100% Speed**\n\nThe code below presents an Easy Python solution with clear syntax. The algorithm works as follows:\n\n1. The numbers of "zeros" in "n!" can be traced by decomposing the multiplication "n * (n-1) * ..." into a prime factorization with the format:\n * n! = 2^a * 3^b * 5^c, ...\n\n2....
35
Given an integer `n`, return _the number of trailing zeroes in_ `n!`. Note that `n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1`. **Example 1:** **Input:** n = 3 **Output:** 0 **Explanation:** 3! = 6, no trailing zero. **Example 2:** **Input:** n = 5 **Output:** 1 **Explanation:** 5! = 120, one trailing zero. **Exa...
null
172: Solution with step by step explanation
factorial-trailing-zeroes
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nTo compute the number of trailing zeroes in n!, we need to count the number of factors of 10 in n!. Notice that 10 can only be formed by multiplying 2 and 5, and we can always find more factors of 2 than factors of 5 in n!. ...
8
Given an integer `n`, return _the number of trailing zeroes in_ `n!`. Note that `n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1`. **Example 1:** **Input:** n = 3 **Output:** 0 **Explanation:** 3! = 6, no trailing zero. **Example 2:** **Input:** n = 5 **Output:** 1 **Explanation:** 5! = 120, one trailing zero. **Exa...
null
Easiest Python Solution
factorial-trailing-zeroes
0
1
\n\n# Code\n```\nclass Solution:\n def trailingZeroes(self, n: int) -> int:\n co = 0\n while n > 0:\n co+= n // 5\n n //= 5\n return co\n```
3
Given an integer `n`, return _the number of trailing zeroes in_ `n!`. Note that `n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1`. **Example 1:** **Input:** n = 3 **Output:** 0 **Explanation:** 3! = 6, no trailing zero. **Example 2:** **Input:** n = 5 **Output:** 1 **Explanation:** 5! = 120, one trailing zero. **Exa...
null
Clear explanation of the solution since I didn't find an adequate one
factorial-trailing-zeroes
0
1
This problem is difficult mainly because you must reach the insight that __it is a multiple of 5 and an even number that leads to a trailing zero__ and since there are on average 4 times as many even numbers as 5s (from 1-9 for example 2,4,6,8), the limiting factor for the number of trailing zeros are the number of 5s ...
32
Given an integer `n`, return _the number of trailing zeroes in_ `n!`. Note that `n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1`. **Example 1:** **Input:** n = 3 **Output:** 0 **Explanation:** 3! = 6, no trailing zero. **Example 2:** **Input:** n = 5 **Output:** 1 **Explanation:** 5! = 120, one trailing zero. **Exa...
null
Python
factorial-trailing-zeroes
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
1
Given an integer `n`, return _the number of trailing zeroes in_ `n!`. Note that `n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1`. **Example 1:** **Input:** n = 3 **Output:** 0 **Explanation:** 3! = 6, no trailing zero. **Example 2:** **Input:** n = 5 **Output:** 1 **Explanation:** 5! = 120, one trailing zero. **Exa...
null
Python3 O(log(n)) time, O(1) space. Explanation
factorial-trailing-zeroes
0
1
To help this intution stick let\'s work with an example, say 60! I can tell you that 60! has 14 trailing zeros.\n\nLet\'s begin by understanding how a trailing zero is created. The simplest way to create a trailing zero is to multiply a given number by 10. Now, every number has at least two factors, namely itself and 1...
12
Given an integer `n`, return _the number of trailing zeroes in_ `n!`. Note that `n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1`. **Example 1:** **Input:** n = 3 **Output:** 0 **Explanation:** 3! = 6, no trailing zero. **Example 2:** **Input:** n = 5 **Output:** 1 **Explanation:** 5! = 120, one trailing zero. **Exa...
null
Very Easy || 100% || Fully Explained || Java || C++|| Python || JS || C || Python3
factorial-trailing-zeroes
1
1
# **Java Solution:**\nRuntime: 0 ms, faster than 100.00% of Java online submissions for Factorial Trailing Zeroes.\n\n```\nclass Solution {\n public int trailingZeroes(int n) {\n // Negative Number Edge Case...\n if (n < 0)\n\t\t return -1;\n // Initialize the output result i.e., the number o...
7
Given an integer `n`, return _the number of trailing zeroes in_ `n!`. Note that `n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1`. **Example 1:** **Input:** n = 3 **Output:** 0 **Explanation:** 3! = 6, no trailing zero. **Example 2:** **Input:** n = 5 **Output:** 1 **Explanation:** 5! = 120, one trailing zero. **Exa...
null
Python beats 99.43%
factorial-trailing-zeroes
0
1
# 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$$O(log(n))$$\n- Space complexity:\n<!-- Add your space complexity here, e.g...
2
Given an integer `n`, return _the number of trailing zeroes in_ `n!`. Note that `n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1`. **Example 1:** **Input:** n = 3 **Output:** 0 **Explanation:** 3! = 6, no trailing zero. **Example 2:** **Input:** n = 5 **Output:** 1 **Explanation:** 5! = 120, one trailing zero. **Exa...
null
Simple solution with In-order Traversal in Binary Tree (Python3 / TypeScript)
binary-search-tree-iterator
0
1
# Intuition\nHere we have:\n- **Binary Search Tree** as `root`\n- our goal is to implement **an iterator** over this tree\n\nWe\'re going to **imitate** an iterator as **traversing** the whole tree **before** extracting.\nWe should store a **pointer**, that represent a current node inside of a `root`.\n\n# Approach\n1....
1
Implement the `BSTIterator` class that represents an iterator over the **[in-order traversal](https://en.wikipedia.org/wiki/Tree_traversal#In-order_(LNR))** of a binary search tree (BST): * `BSTIterator(TreeNode root)` Initializes an object of the `BSTIterator` class. The `root` of the BST is given as part of the co...
null
[Python] TC O(1) SC O(h) Generator Solution
binary-search-tree-iterator
0
1
### Explanation\n\nOne way to only use O(h) space is to utilise a generator for our inorder traversal. We can implement it as such:\n\n```python\ndef inorder(node: Optional[TreeNode]) -> Generator[int, None, None]:\n """\n Generator function that takes the root node of a binary tree\n and iterates through the ...
50
Implement the `BSTIterator` class that represents an iterator over the **[in-order traversal](https://en.wikipedia.org/wiki/Tree_traversal#In-order_(LNR))** of a binary search tree (BST): * `BSTIterator(TreeNode root)` Initializes an object of the `BSTIterator` class. The `root` of the BST is given as part of the co...
null
[python] 3 different approaches and step by step optimisation [faster than 98%, 88% less space ]
binary-search-tree-iterator
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSince we have to do the in-order tranversal and print the next node in in-order. We can do it in 3 different ways\n1. Create an inorder array inside class constructor recursively and maintain an index to track current element \n2. Maintai...
7
Implement the `BSTIterator` class that represents an iterator over the **[in-order traversal](https://en.wikipedia.org/wiki/Tree_traversal#In-order_(LNR))** of a binary search tree (BST): * `BSTIterator(TreeNode root)` Initializes an object of the `BSTIterator` class. The `root` of the BST is given as part of the co...
null
173: Solution with step by step explanation
binary-search-tree-iterator
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nThe main idea behind this solution is to implement an iterator that returns the nodes in the in-order traversal of the binary search tree. We can use a stack to keep track of the nodes we need to visit.\n\n- In the construct...
10
Implement the `BSTIterator` class that represents an iterator over the **[in-order traversal](https://en.wikipedia.org/wiki/Tree_traversal#In-order_(LNR))** of a binary search tree (BST): * `BSTIterator(TreeNode root)` Initializes an object of the `BSTIterator` class. The `root` of the BST is given as part of the co...
null
Python || 94.82% Faster || Easy || Iterative Solution
binary-search-tree-iterator
0
1
```\nclass BSTIterator:\n st=[]\n def __init__(self, root: Optional[TreeNode]):\n self.pushall(root)\n\n def next(self) -> int:\n temp=self.st.pop()\n self.pushall(temp.right)\n return temp.val\n\n def hasNext(self) -> bool:\n return True if len(self.st)>0 else False\n\n ...
5
Implement the `BSTIterator` class that represents an iterator over the **[in-order traversal](https://en.wikipedia.org/wiki/Tree_traversal#In-order_(LNR))** of a binary search tree (BST): * `BSTIterator(TreeNode root)` Initializes an object of the `BSTIterator` class. The `root` of the BST is given as part of the co...
null
Python 96% faster
binary-search-tree-iterator
0
1
```\n# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass BSTIterator:\n\n def __init__(self, root: Optional[TreeNode]):\n self.stack = []\n cur = root\...
2
Implement the `BSTIterator` class that represents an iterator over the **[in-order traversal](https://en.wikipedia.org/wiki/Tree_traversal#In-order_(LNR))** of a binary search tree (BST): * `BSTIterator(TreeNode root)` Initializes an object of the `BSTIterator` class. The `root` of the BST is given as part of the co...
null
Python3 solution | Iterative inorder traversal
binary-search-tree-iterator
0
1
```\nclass BSTIterator:\n def __init__(self, root: Optional[TreeNode]):\n self.root = root\n self.iter = iter(self.iterativeInorder())\n self.nextValue = -1\n\n def iterativeInorder(self) :\n stack = []\n curr = self.root\n while True :\n if curr is not None :\...
1
Implement the `BSTIterator` class that represents an iterator over the **[in-order traversal](https://en.wikipedia.org/wiki/Tree_traversal#In-order_(LNR))** of a binary search tree (BST): * `BSTIterator(TreeNode root)` Initializes an object of the `BSTIterator` class. The `root` of the BST is given as part of the co...
null
Python3 O(H) solution with stacks.
binary-search-tree-iterator
0
1
```\nclass BSTIterator:\n\n def __init__(self, root: Optional[TreeNode]):\n self.root = root\n self.stack = []\n while root:\n self.stack.append(root)\n root = root.left\n \n\n def next(self) -> int:\n if self.stack:\n x = self.stack[-1]\n ...
1
Implement the `BSTIterator` class that represents an iterator over the **[in-order traversal](https://en.wikipedia.org/wiki/Tree_traversal#In-order_(LNR))** of a binary search tree (BST): * `BSTIterator(TreeNode root)` Initializes an object of the `BSTIterator` class. The `root` of the BST is given as part of the co...
null
python3 + binary search and dp
dungeon-game
0
1
\n# Code\n```\nclass Solution:\n def calculateMinimumHP(self, dungeon: List[List[int]]) -> int:\n r = len(dungeon)\n c = len(dungeon[0])\n\n def possible(n):\n mat = [[-math.inf for x in range(c)] for _ in range(r)]\n mat[0][0] = n+dungeon[0][0]\n for row in rang...
0
The demons had captured the princess and imprisoned her in **the bottom-right corner** of a `dungeon`. The `dungeon` consists of `m x n` rooms laid out in a 2D grid. Our valiant knight was initially positioned in **the top-left room** and must fight his way through `dungeon` to rescue the princess. The knight has an i...
null
Python DP Solution
dungeon-game
0
1
# Intuition\nWhen tackling DP problems, remember to first figure out the underlying state transfer equation. \n\nIn this question, it is not simply the shortest path question, since we only care about the minimum starting HP. Hence to find out the initial HP needed at pos (i, j), we need to find out how much HP do we n...
1
The demons had captured the princess and imprisoned her in **the bottom-right corner** of a `dungeon`. The `dungeon` consists of `m x n` rooms laid out in a 2D grid. Our valiant knight was initially positioned in **the top-left room** and must fight his way through `dungeon` to rescue the princess. The knight has an i...
null
DYNAMIC PROGRAMMING
dungeon-game
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition behind this solution is to use dynamic programming to store the minimum health required to reach each cell in a 2D array, and then calculate the minimum health required to reach each cell by taking the minimum of the health ...
1
The demons had captured the princess and imprisoned her in **the bottom-right corner** of a `dungeon`. The `dungeon` consists of `m x n` rooms laid out in a 2D grid. Our valiant knight was initially positioned in **the top-left room** and must fight his way through `dungeon` to rescue the princess. The knight has an i...
null
174: Solution with step by step explanation
dungeon-game
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nThis solution uses dynamic programming to solve the problem. The main idea is to build a 2D array dp to store the minimum initial health required at each position to reach the bottom-right corner. We start from the bottom-ri...
3
The demons had captured the princess and imprisoned her in **the bottom-right corner** of a `dungeon`. The `dungeon` consists of `m x n` rooms laid out in a 2D grid. Our valiant knight was initially positioned in **the top-left room** and must fight his way through `dungeon` to rescue the princess. The knight has an i...
null
Easy Python3 solution
dungeon-game
0
1
Not pretending for unique solution, but I hope that my code will be easy to understand.\n\nThe main idea is that we go reversed and compare ``max(1, min(previous_cells_values))``. That\'s the key. \n\nWhy do we compare max with 1? Because we don\'t need extra 30 hp, only 1 to be alive.\n\n\n```\nclass Solution:\n de...
20
The demons had captured the princess and imprisoned her in **the bottom-right corner** of a `dungeon`. The `dungeon` consists of `m x n` rooms laid out in a 2D grid. Our valiant knight was initially positioned in **the top-left room** and must fight his way through `dungeon` to rescue the princess. The knight has an i...
null
Easy Solution Using Functools
largest-number
0
1
# 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
Given a list of non-negative integers `nums`, arrange them such that they form the largest number and return it. Since the result may be very large, so you need to return a string instead of an integer. **Example 1:** **Input:** nums = \[10,2\] **Output:** "210 " **Example 2:** **Input:** nums = \[3,30,34,5,9\] *...
null
179: Solution with step by step explanation
largest-number
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nTo solve this problem, we need to sort the given list of numbers such that they form the largest possible number. To do this, we need to create a custom sorting function that compares two numbers at a time and concatenates t...
20
Given a list of non-negative integers `nums`, arrange them such that they form the largest number and return it. Since the result may be very large, so you need to return a string instead of an integer. **Example 1:** **Input:** nums = \[10,2\] **Output:** "210 " **Example 2:** **Input:** nums = \[3,30,34,5,9\] *...
null
Simple solution using Sort and String Comparison , Python
largest-number
0
1
# Code\n```\nclass Solution:\n def largestNumber(self, nums: List[int]) -> str:\n lst = []\n\n for ele in nums:\n lst += [str(ele)]\n \n n = len(lst)\n\n for i in range(n):\n for j in range(i+1 , n):\n \n if str(lst[i]) + str(lst[...
9
Given a list of non-negative integers `nums`, arrange them such that they form the largest number and return it. Since the result may be very large, so you need to return a string instead of an integer. **Example 1:** **Input:** nums = \[10,2\] **Output:** "210 " **Example 2:** **Input:** nums = \[3,30,34,5,9\] *...
null
[Python] Proper Python 3 without Resorting to cmp_to_key(), The Best
largest-number
0
1
# Complexity\n- Time complexity: $$O(n\\log n\\log N)$$\n- Space complexity: $$O(n\\log N)$$\n\nThe Best!\n\n# Code\n```\nclass Solution:\n def largestNumber(self, nums: List[int]) -> str:\n nums[:] = map(str, nums)\n nums.sort(key=NumCompare, reverse=True)\n return \'\'.join(nums).lstrip(\'0\')...
2
Given a list of non-negative integers `nums`, arrange them such that they form the largest number and return it. Since the result may be very large, so you need to return a string instead of an integer. **Example 1:** **Input:** nums = \[10,2\] **Output:** "210 " **Example 2:** **Input:** nums = \[3,30,34,5,9\] *...
null
python easy custom sort solution!!!!!!!
largest-number
0
1
My solution is based on this obvious math inference:\nx: n digit; y: m digit\nif xy > yx,\nthen 10^m * x + y > 10^n * y + x\nthen x / (10^n - 1) > y / (10^m - 1)\nso we could use this method to make a sorting custom key.\n\n\n```\nclass Solution:\n def largestNumber(self, nums: List[int]) -> str:\n nums = so...
22
Given a list of non-negative integers `nums`, arrange them such that they form the largest number and return it. Since the result may be very large, so you need to return a string instead of an integer. **Example 1:** **Input:** nums = \[10,2\] **Output:** "210 " **Example 2:** **Input:** nums = \[3,30,34,5,9\] *...
null
Python 3 Simple Solution Explained (video + code)
largest-number
0
1
[](https://www.youtube.com/watch?v=xH3fgc8Q7Xc)\nhttps://www.youtube.com/watch?v=xH3fgc8Q7Xc\n```\nclass Solution:\n def largestNumber(self, nums: List[int]) -> str:\n if not any(map(bool, nums)):\n return \'0\'\n \n nums = list(map(str, nums))\n if len(nums) < 2:\n ...
28
Given a list of non-negative integers `nums`, arrange them such that they form the largest number and return it. Since the result may be very large, so you need to return a string instead of an integer. **Example 1:** **Input:** nums = \[10,2\] **Output:** "210 " **Example 2:** **Input:** nums = \[3,30,34,5,9\] *...
null
[Python] Detailed Explanation with comparator
largest-number
0
1
```\nclass Solution:\n def largestNumber(self, nums: List[int]) -> str:\n ## RC ##\n ## APPROACH : CUSTOM SORTING WITH COMPARATOR ##\n ## MAIN IDEA : It\'s all about comparison . We define a func that compares two strings a ,b. we consider a bigger than b if a+b > b+a . then we sort the numbers ...
27
Given a list of non-negative integers `nums`, arrange them such that they form the largest number and return it. Since the result may be very large, so you need to return a string instead of an integer. **Example 1:** **Input:** nums = \[10,2\] **Output:** "210 " **Example 2:** **Input:** nums = \[3,30,34,5,9\] *...
null
Beating 94.90% Shortest and Easiest Python Solution
largest-number
0
1
![image.png](https://assets.leetcode.com/users/images/402c7192-0ad6-4890-b89a-ffe3bc6f4f40_1679892588.115939.png)\n\n# Code\n```\nclass Solution:\n def largestNumber(self, nums: List[int]) -> str:\n a = \'\'.join(sorted([str(a) for a in nums], \n key=lambda a: ((str(a)*9)[:9],a), \n ...
1
Given a list of non-negative integers `nums`, arrange them such that they form the largest number and return it. Since the result may be very large, so you need to return a string instead of an integer. **Example 1:** **Input:** nums = \[10,2\] **Output:** "210 " **Example 2:** **Input:** nums = \[3,30,34,5,9\] *...
null
Python Solution
largest-number
0
1
# 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
Given a list of non-negative integers `nums`, arrange them such that they form the largest number and return it. Since the result may be very large, so you need to return a string instead of an integer. **Example 1:** **Input:** nums = \[10,2\] **Output:** "210 " **Example 2:** **Input:** nums = \[3,30,34,5,9\] *...
null
Brute Force solution in Python
repeated-dna-sequences
0
1
# Intuition\nWe just need to return a list of substrings which appeared more than once.\n\n# Approach\nIf length of string is less than or equal to 10, no substring could be repeated so an empty list is returned. Else, starting from 0th index, substrings of length 10 are stored in list1. If a substring is already prese...
1
The **DNA sequence** is composed of a series of nucleotides abbreviated as `'A'`, `'C'`, `'G'`, and `'T'`. * For example, `"ACGAATTCCG "` is a **DNA sequence**. When studying **DNA**, it is useful to identify repeated sequences within the DNA. Given a string `s` that represents a **DNA sequence**, return all the *...
null
187: Solution with step by step explanation
repeated-dna-sequences
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nStep-by-step explanation:\n\n1. Define a class named Solution that will contain the method to solve the problem.\n\n2. Define a method named findRepeatedDnaSequences that takes in a string s representing a DNA sequence and r...
5
The **DNA sequence** is composed of a series of nucleotides abbreviated as `'A'`, `'C'`, `'G'`, and `'T'`. * For example, `"ACGAATTCCG "` is a **DNA sequence**. When studying **DNA**, it is useful to identify repeated sequences within the DNA. Given a string `s` that represents a **DNA sequence**, return all the *...
null
O(n) time | O(n) space | solution explained
repeated-dna-sequences
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUse a hashset and search for repeated sequences (10-size substring). Add the repeated sequences to the result.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- set res = a hash set to store the repeated sequences ...
2
The **DNA sequence** is composed of a series of nucleotides abbreviated as `'A'`, `'C'`, `'G'`, and `'T'`. * For example, `"ACGAATTCCG "` is a **DNA sequence**. When studying **DNA**, it is useful to identify repeated sequences within the DNA. Given a string `s` that represents a **DNA sequence**, return all the *...
null
Simple 🐍 python solution✔
repeated-dna-sequences
0
1
\n\n# Code\n```\nclass Solution:\n def findRepeatedDnaSequences(self, s: str) -> List[str]:\n visited = {}\n res = []\n for i in range(len(s) - 9):\n sequence = s[i:i+10]\n if sequence in visited:\n if not visited[sequence]:\n visited[seque...
2
The **DNA sequence** is composed of a series of nucleotides abbreviated as `'A'`, `'C'`, `'G'`, and `'T'`. * For example, `"ACGAATTCCG "` is a **DNA sequence**. When studying **DNA**, it is useful to identify repeated sequences within the DNA. Given a string `s` that represents a **DNA sequence**, return all the *...
null
Python || Easy for Beginners || O(N)
repeated-dna-sequences
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n###### We can use the ***dictionary*** to solve this problem easily. \n\n# Approach\n1. Find the length of the string. if ***length is less than or equal to 10***, return ***empty list***.\n2. Using ***dictionary*** to get the count of t...
4
The **DNA sequence** is composed of a series of nucleotides abbreviated as `'A'`, `'C'`, `'G'`, and `'T'`. * For example, `"ACGAATTCCG "` is a **DNA sequence**. When studying **DNA**, it is useful to identify repeated sequences within the DNA. Given a string `s` that represents a **DNA sequence**, return all the *...
null
Simple Python Code
repeated-dna-sequences
0
1
\n\n# Code\n```\nclass Solution:\n def findRepeatedDnaSequences(self, s: str) -> List[str]:\n l=[]\n seen=set()\n dna=\'\'\n if len(s)>=10:\n for i in range(len(s)):\n dna=s[i:i+10]\n if dna in seen:\n if dna not in l:\n ...
2
The **DNA sequence** is composed of a series of nucleotides abbreviated as `'A'`, `'C'`, `'G'`, and `'T'`. * For example, `"ACGAATTCCG "` is a **DNA sequence**. When studying **DNA**, it is useful to identify repeated sequences within the DNA. Given a string `s` that represents a **DNA sequence**, return all the *...
null
Python || Simple
repeated-dna-sequences
0
1
\n\n# Code\n```\nclass Solution:\n def findRepeatedDnaSequences(self, s: str) -> List[str]:\n res=set()\n seen=set()\n for i in range(len(s)-9):\n curr=s[i:i+10]\n if curr in seen:\n res.add(curr)\n seen.add(curr)\n return list(res)\n\n```
2
The **DNA sequence** is composed of a series of nucleotides abbreviated as `'A'`, `'C'`, `'G'`, and `'T'`. * For example, `"ACGAATTCCG "` is a **DNA sequence**. When studying **DNA**, it is useful to identify repeated sequences within the DNA. Given a string `s` that represents a **DNA sequence**, return all the *...
null
[Python] 2 solutions - HashTable & Rolling Hash - Clean & Concise
repeated-dna-sequences
0
1
**\u2714\uFE0F Solution 1: Hashtable**\n```python3\nclass Solution(object):\n def findRepeatedDnaSequences(self, s):\n n = len(s)\n cnt = defaultdict(int)\n ans = []\n\n for i in range(n - 9):\n dna = s[i:i+10]\n cnt[dna] += 1\n if cnt[dna] == 2:\n ...
32
The **DNA sequence** is composed of a series of nucleotides abbreviated as `'A'`, `'C'`, `'G'`, and `'T'`. * For example, `"ACGAATTCCG "` is a **DNA sequence**. When studying **DNA**, it is useful to identify repeated sequences within the DNA. Given a string `s` that represents a **DNA sequence**, return all the *...
null
Easy Python3 Sliding Window Hashmap/Set Solution
repeated-dna-sequences
0
1
# 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...
3
The **DNA sequence** is composed of a series of nucleotides abbreviated as `'A'`, `'C'`, `'G'`, and `'T'`. * For example, `"ACGAATTCCG "` is a **DNA sequence**. When studying **DNA**, it is useful to identify repeated sequences within the DNA. Given a string `s` that represents a **DNA sequence**, return all the *...
null
Python3 Rabin-Karp
repeated-dna-sequences
0
1
# Intuition\nUse bitmasking rolling hash procedure to produce hash of each 10-character sequence so we don\'t have to create a new substring just to check if the substring has been visited before.\n\n# Approach\nAssign each of the four possible characters a unique binary number\n\n# Complexity\n- Time complexity:\nO(n)...
1
The **DNA sequence** is composed of a series of nucleotides abbreviated as `'A'`, `'C'`, `'G'`, and `'T'`. * For example, `"ACGAATTCCG "` is a **DNA sequence**. When studying **DNA**, it is useful to identify repeated sequences within the DNA. Given a string `s` that represents a **DNA sequence**, return all the *...
null
Easy python solution
repeated-dna-sequences
0
1
\n# Code\n```\nclass Solution:\n def findRepeatedDnaSequences(self, s: str) -> List[str]:\n lst=[]\n set1=set()\n for i in range(0,len(s)-9):\n tmp=s[i:i+10]\n if tmp not in set1:\n set1.add(tmp)\n else:\n lst.append(tmp)\n re...
2
The **DNA sequence** is composed of a series of nucleotides abbreviated as `'A'`, `'C'`, `'G'`, and `'T'`. * For example, `"ACGAATTCCG "` is a **DNA sequence**. When studying **DNA**, it is useful to identify repeated sequences within the DNA. Given a string `s` that represents a **DNA sequence**, return all the *...
null
Python O(n) by set and iteration [w/ Comment]
repeated-dna-sequences
0
1
Python O(n) by set and iteration\n\n---\n\n**Implementation** by set and iteration\n\n```\nclass Solution:\n def findRepeatedDnaSequences(self, s: str) -> List[str]:\n \n # set for sequence\n sequence = set()\n \n # set for sequence with repetition\n repeated = set()\n ...
16
The **DNA sequence** is composed of a series of nucleotides abbreviated as `'A'`, `'C'`, `'G'`, and `'T'`. * For example, `"ACGAATTCCG "` is a **DNA sequence**. When studying **DNA**, it is useful to identify repeated sequences within the DNA. Given a string `s` that represents a **DNA sequence**, return all the *...
null
python 3 || simple hash map solution
repeated-dna-sequences
0
1
```\nclass Solution:\n def findRepeatedDnaSequences(self, s: str) -> List[str]:\n seen = {}\n res = []\n \n for i in range(len(s) - 9):\n sequence = s[i:i+10]\n if sequence in seen:\n if not seen[sequence]:\n seen[sequence] = True\n ...
2
The **DNA sequence** is composed of a series of nucleotides abbreviated as `'A'`, `'C'`, `'G'`, and `'T'`. * For example, `"ACGAATTCCG "` is a **DNA sequence**. When studying **DNA**, it is useful to identify repeated sequences within the DNA. Given a string `s` that represents a **DNA sequence**, return all the *...
null
3-D Bottom-Up Dynamic Programming Solution Python3
best-time-to-buy-and-sell-stock-iv
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nuse dp to find out the max profit for all days using t transactions while keeping track of having the stock or not\n\nonly selling counts as an extra transaction\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\ndp[i...
1
You are given an integer array `prices` where `prices[i]` is the price of a given stock on the `ith` day, and an integer `k`. Find the maximum profit you can achieve. You may complete at most `k` transactions: i.e. you may buy at most `k` times and sell at most `k` times. **Note:** You may not engage in multiple tran...
null
Solution
best-time-to-buy-and-sell-stock-iv
1
1
```C++ []\n#include <stack>\n#include <vector>\n#include <utility>\n#include <algorithm>\n#include <numeric>\nusing std::stack;\nusing std::pair;\nusing std::vector;\nusing std::nth_element;\nusing std::accumulate;\n\nclass Solution {\n\npublic:\n int maxProfit(int k, const vector<int>& prices) {\n vector<int...
206
You are given an integer array `prices` where `prices[i]` is the price of a given stock on the `ith` day, and an integer `k`. Find the maximum profit you can achieve. You may complete at most `k` transactions: i.e. you may buy at most `k` times and sell at most `k` times. **Note:** You may not engage in multiple tran...
null
Dynamic programming with iterations notebook - Best time to buy and sell stock problem
best-time-to-buy-and-sell-stock-iv
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem is Markov: we only care how much cash we have in hand and if stock is head. The state variables should be therefore `(time=i, stock_held=0 or 1)`; the state transition function:\n `dp[i][0] = max(dp[i-1][0],\n ...
0
You are given an integer array `prices` where `prices[i]` is the price of a given stock on the `ith` day, and an integer `k`. Find the maximum profit you can achieve. You may complete at most `k` transactions: i.e. you may buy at most `k` times and sell at most `k` times. **Note:** You may not engage in multiple tran...
null
Python3 / Rust / Java/ JavaScript - Dynamic Programming
best-time-to-buy-and-sell-stock-iv
1
1
# Intuition\nThe given code solves the problem of finding the maximum profit achievable by making at most $$k$$ transactions in a given $$prices$$ list.\n\n# Approach\n1. The code initializes a 2D list $$transactions$$, where each row represents a transaction, and the columns represent the minimum buying price and maxi...
1
You are given an integer array `prices` where `prices[i]` is the price of a given stock on the `ith` day, and an integer `k`. Find the maximum profit you can achieve. You may complete at most `k` transactions: i.e. you may buy at most `k` times and sell at most `k` times. **Note:** You may not engage in multiple tran...
null
🔥 [LeetCode The Hard Way] 🔥 7 Lines | Line By Line Explanation
best-time-to-buy-and-sell-stock-iv
0
1
Please check out [LeetCode The Hard Way](https://wingkwong.github.io/leetcode-the-hard-way/) for more solution explanations and tutorials. \nI\'ll explain my solution line by line daily and you can find the full list in my [Discord](https://discord.gg/Nqm4jJcyBf).\nIf you like it, please give a star, watch my [Github R...
83
You are given an integer array `prices` where `prices[i]` is the price of a given stock on the `ith` day, and an integer `k`. Find the maximum profit you can achieve. You may complete at most `k` transactions: i.e. you may buy at most `k` times and sell at most `k` times. **Note:** You may not engage in multiple tran...
null
Easy python 15 line DP solution
best-time-to-buy-and-sell-stock-iv
0
1
```\nclass Solution:\n def maxProfit(self, k: int, prices: List[int]) -> int:\n def func(i,buy,prices,ct,dic):\n if i>=len(prices) or ct==0:\n return 0\n if (i,buy,ct) in dic:\n return dic[(i,buy,ct)]\n x,y,a,b=0,0,0,0\n if buy:\n ...
4
You are given an integer array `prices` where `prices[i]` is the price of a given stock on the `ith` day, and an integer `k`. Find the maximum profit you can achieve. You may complete at most `k` transactions: i.e. you may buy at most `k` times and sell at most `k` times. **Note:** You may not engage in multiple tran...
null
Python Solution || Faster Than 98.22% Of Python Submissions || Easy To Read
best-time-to-buy-and-sell-stock-iv
0
1
```\nclass Solution:\n def maxProfit(self, k: int, prices: List[int]) -> int:\n buy = [inf for _ in range(k+1)]\n profit = [0 for _ in range(k+1)]\n for currPrice in prices:\n for i in range(1, k+1):\n buy[i] = min(buy[i], currPrice - profit[i-1])\n profi...
1
You are given an integer array `prices` where `prices[i]` is the price of a given stock on the `ith` day, and an integer `k`. Find the maximum profit you can achieve. You may complete at most `k` transactions: i.e. you may buy at most `k` times and sell at most `k` times. **Note:** You may not engage in multiple tran...
null
Simple Dp Solution using Python
best-time-to-buy-and-sell-stock-iv
0
1
\n\n# Code\n```\nclass Solution:\n def maxProfit(self, k: int, prices: List[int]) -> int:\n # Similar to 123. Best Time to Buy and Sell Stock III\n \n n = len(prices)\n dp = [[[0 for m in range(k+1)] for i in range(3)] for j in range(n+1)]\n\n # Tabulation ..!!!!\n \n ...
2
You are given an integer array `prices` where `prices[i]` is the price of a given stock on the `ith` day, and an integer `k`. Find the maximum profit you can achieve. You may complete at most `k` transactions: i.e. you may buy at most `k` times and sell at most `k` times. **Note:** You may not engage in multiple tran...
null
Python Striver Solution O(N*K) Easy Solution ✔
best-time-to-buy-and-sell-stock-iv
0
1
# Recursive :\n```\n\nclass Solution:\n def f(self,ind,transNo,n,k,price):\n if ind==n or transNo==2*k:\n return 0\n\n if transNo%2==0: #buy\n profit=max(-price[ind] + self.f(ind+1,transNo+1,n,k,price),\n 0 + self.f(ind+1,transNo,n,k,price))\n ...
4
You are given an integer array `prices` where `prices[i]` is the price of a given stock on the `ith` day, and an integer `k`. Find the maximum profit you can achieve. You may complete at most `k` transactions: i.e. you may buy at most `k` times and sell at most `k` times. **Note:** You may not engage in multiple tran...
null