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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
get-the-size-of-a-dataframe | beginners soln with explaination | beginners-soln-with-explaination-by-dars-1ojy | Intuition\n Describe your first thoughts on how to solve this problem. \nGiven a DataFrame players, we need to determine the number of rows and columns. This ca | Darshan_999 | NORMAL | 2024-07-02T15:33:35.378551+00:00 | 2024-07-02T15:33:35.378586+00:00 | 317 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nGiven a DataFrame `players`, we need to determine the number of rows and columns. This can be done by utilizing the DataFrame\'s `axes` attribute, which provides access to the row and column labels.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. **Extract Rows and Columns**: Use the `axes` attribute of the DataFrame. `axes[0]` gives the index (rows), and `axes[1]` gives the columns.\n2. **Calculate Lengths**: Determine the number of rows by getting the length of `axes[0]`, and the number of columns by getting the length of `axes[1]`.\n3. **Return Result**: Return a list containing the number of rows and columns.\n\n# Complexity\n- Time complexity: \n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(1)$$ - The operations to get the lengths of the axes are constant time operations.\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(1)$$ - No additional space is used other than a few variables for storing the lengths.\n\n# Code\n```python\nimport pandas as pd\nfrom typing import List\n\ndef getDataframeSize(players: pd.DataFrame) -> List[int]:\n rows = len(players.axes[0])\n cols = len(players.axes[1])\n return [rows, cols]\n```\n\nThis function effectively retrieves the size of a DataFrame in terms of the number of rows and columns. | 2 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | 2878. Get the Size of a DataFrame | 2878-get-the-size-of-a-dataframe-by-dele-cdz5 | Intuition\nThe task appears to involve finding the size of a DataFrame, which likely means determining the number of rows and columns it contains. This can be a | deleted_user | NORMAL | 2024-06-08T18:36:42.271795+00:00 | 2024-06-08T18:36:42.271823+00:00 | 545 | false | # Intuition\nThe task appears to involve finding the size of a DataFrame, which likely means determining the number of rows and columns it contains. This can be accomplished using Pandas DataFrame attributes.\n# Approach\nTo find the number of rows and columns in the DataFrame, we can use the axes attribute of the DataFrame object. The axes[0] gives the row axis and axes[1] gives the column axis. We\'ll simply take the length of these axes to find the number of rows and columns.\n\n\n# Complexity\n- ## Time complexity:\nAccessing the axes attribute of the DataFrame takes constant time.\nFinding the length of the axes requires traversing the axes once, so it\'s linear in the number of axes.\nOverall time complexity is \nO(n), where n is the maximum of the number of rows and columns in the DataFrame.\n\n- ## Space complexity:\nWe are only storing the lengths of rows and columns, so the space complexity is constant, i.e., \nO(1).\n\n# Code : \n\nThis function getDataframeSize takes a Pandas DataFrame players as input and returns a list containing the number of rows and columns in the DataFrame.\n\n```.py\nimport pandas as pd\n\ndef getDataframeSize(players: pd.DataFrame) -> List[int]:\n rows = len(players.axes[0])\n cols = len(players.axes[1])\n return [rows,cols]\n``` | 2 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | β
βοΈ Best Pandas Solution with simple meaning of every line | best-pandas-solution-with-simple-meaning-40ao | \n\npython\nimport pandas as pd\n\n- import pandas as pd: Imports the Pandas library and assigns it the alias pd, allowing us to refer to Pandas functions and c | sgupta99299 | NORMAL | 2024-03-24T16:54:03.014387+00:00 | 2024-03-24T16:54:03.014422+00:00 | 208 | false | \n\n```python\nimport pandas as pd\n```\n- `import pandas as pd`: Imports the Pandas library and assigns it the alias `pd`, allowing us to refer to Pandas functions and classes using `pd`.\n\n```python\ndef getDataframeSize(players: pd.DataFrame) -> List[int]:\n```\n- `def getDataframeSize(players: pd.DataFrame) -> List[int]:`: Defines a function named `getDataframeSize` that takes one argument, `players`, which is expected to be a Pandas DataFrame. It specifies that the function returns a list of integers. This function seems to retrieve the number of rows and columns in the input DataFrame `players`.\n\n```python\n row, col = players.shape\n```\n- `row, col = players.shape`: Retrieves the shape of the DataFrame `players`, which returns a tuple containing the number of rows and columns in the DataFrame. The variables `row` and `col` are assigned the respective values from this tuple.\n\n```python\n return [row, col]\n```\n- `return [row, col]`: Returns a list containing the number of rows and columns in the DataFrame `players`.\n\n\n# Code\n```\nimport pandas as pd\n\ndef getDataframeSize(players: pd.DataFrame) -> List[int]:\n row, col = players.shape\n return [row, col]\n``` | 2 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | using .shape | using-shape-by-vijit_verma-sp6c | Intuition\n Describe your first thoughts on how to solve this problem. \nresultcan be obtained by return the shape , but we have to convert it to list as the re | Vijit_verma1023 | NORMAL | 2024-03-16T15:59:27.761235+00:00 | 2024-03-16T15:59:27.761264+00:00 | 832 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nresultcan be obtained by return the shape , but we have to convert it to list as the return type of it is tuple \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)$$ -->\n\n# Code\n```\nimport pandas as pd\n\ndef getDataframeSize(players: pd.DataFrame) -> List[int]:\n result=list(players.shape)\n return result\n``` | 2 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | pandas solution | pandas-solution-by-user2368jd-kid3 | 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 | user2368Jd | NORMAL | 2024-01-05T16:05:58.725372+00:00 | 2024-01-05T16:05:58.725395+00:00 | 2,936 | 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)$$ -->\n\n# Code\n```\nimport pandas as pd\n\ndef getDataframeSize(players: pd.DataFrame) -> List[int]:\n r,c=players.shape\n return [r,c]\n``` | 2 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Easy to understand code | easy-to-understand-code-by-andersongarce-3xds | Upvote \n\n# Code\n\nimport pandas as pd\n\ndef getDataframeSize(players: pd.DataFrame) -> List[int]:\n num_rows, num_columns = players.shape\n return [nu | andersongarcesmolina | NORMAL | 2023-11-11T20:38:51.141725+00:00 | 2023-11-11T20:38:51.141749+00:00 | 1,600 | false | # Upvote \n\n# Code\n```\nimport pandas as pd\n\ndef getDataframeSize(players: pd.DataFrame) -> List[int]:\n num_rows, num_columns = players.shape\n return [num_rows, num_columns]\n\n``` | 2 | 0 | ['Pandas'] | 1 |
get-the-size-of-a-dataframe | Simple One Line Solution || Beat 100% || | simple-one-line-solution-beat-100-by-yas-etoh | Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \nO(1)\n- Space complexity:\n Add your space complexity here, e.g. O(n) \nO(1)\n# Code | yashmenaria | NORMAL | 2023-10-06T04:16:36.549219+00:00 | 2023-10-06T04:16:36.549242+00:00 | 7 | false | # Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(1)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n# Code\n```\nimport pandas as pd\n\ndef getDataframeSize(players: pd.DataFrame) -> List[int]:\n return list(players.shape)\n``` | 2 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Shape with explanation | shape-with-explanation-by-salvadordali-269h | Intuition\n\nDataframe has many different properties, but the one we care is df.shape which produces a tuple. All we need to convert it to list\n\n\n# Code\n\ni | salvadordali | NORMAL | 2023-10-04T05:13:46.931223+00:00 | 2023-10-04T05:13:46.931253+00:00 | 1,577 | false | # Intuition\n\nDataframe has many different properties, but the one we care is [df.shape](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.shape.html) which produces a tuple. All we need to convert it to list\n\n\n# Code\n```\nimport pandas as pd\n\ndef getDataframeSize(df: pd.DataFrame) -> List[int]:\n return list(df.shape)\n``` | 2 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Beats 92% π² || One-Line Self Explanatory Solution β‘π₯ || O(1) Time complexity π | beats-92-one-line-self-explanatory-solut-z6iy | IntuitionThe problem requires finding the number of rows and columns in a given Pandas DataFrame.
Pandas provides built-in attributes to efficiently determine t | abirmazumdar14798 | NORMAL | 2025-03-22T06:23:43.315506+00:00 | 2025-03-22T06:23:43.315506+00:00 | 337 | false | # Intuition
The problem requires finding the number of rows and columns in a given Pandas DataFrame.
Pandas provides built-in attributes to efficiently determine the shape of a DataFrame.
# Approach
1. Use `players.index.size` to get the number of rows in the DataFrame.
2. Use `players.columns.size` to get the number of columns in the DataFrame.
3. Store both values in a list and return it.
# Complexity
- **Time complexity:**
- Accessing `index.size` and `columns.size` takes **O(1)** since they are direct attribute lookups.
- **Overall:** $$O(1)$$.
- **Space complexity:**
- The function returns a list of two integers, which takes **O(1)** space.
- **Overall:** $$O(1)$$.
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
lst=[players.index.size,players.columns.size]
return lst
``` | 1 | 0 | ['Python3', 'Pandas'] | 0 |
get-the-size-of-a-dataframe | Solution for Size of Dataframe in Python using Pandas. | solution-for-size-of-dataframe-in-python-bud8 | IntuitionThis was a straightforward problem with no detailed solution.ApproachWe use pandas as pd by importing it. Then we just use the shape member of the Data | aahan0511 | NORMAL | 2025-03-20T05:30:11.929715+00:00 | 2025-03-20T05:30:11.929715+00:00 | 150 | false | # Intuition
This was a straightforward problem with no detailed solution.
# Approach
We use `pandas` as `pd` by importing it. Then we just use the `shape` member of the `Dataframe` which gives the 2 dimensions of a `Dataframe`, which is what we want, but as the `.shape` is a tuple, we convert it to a `list()`.
# Complexity
- Time complexity: `O(1)`| *Beats 81.04%*
- Space complexity: `O(1)`| *Beats 73.23%*
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> list[int]:
return list(players.shape)
```
# Proof

# Support
If you liked this explanation and solution please **`upvote`**.
| 1 | 0 | ['Array', 'Database', 'Pandas'] | 0 |
get-the-size-of-a-dataframe | Pandas | pandas-by-adchoudhary-rdkn | Code | adchoudhary | NORMAL | 2025-02-28T02:38:52.203704+00:00 | 2025-02-28T02:38:52.203704+00:00 | 200 | false | # Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return [players.shape[0], players.shape[1]]
``` | 1 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Easy Beginner Solution || Best Solution | easy-beginner-solution-best-solution-by-r4p34 | IntuitionThe problem requires retrieving the dimensions of a given Pandas DataFrame. The shape attribute of a DataFrame returns a tuple (rows, columns), which d | justprakhar | NORMAL | 2025-02-26T18:08:35.809204+00:00 | 2025-02-26T18:08:35.809204+00:00 | 233 | false | # Intuition
The problem requires retrieving the dimensions of a given Pandas DataFrame. The shape attribute of a DataFrame returns a tuple (rows, columns), which directly gives us the required information.
# Approach
1. Use shape attribute: The players.shape provides a tuple containing the number of rows and columns in the DataFrame.
2. Convert to list: Since the expected output format is a list, we simply convert the tuple to a list using list(players.shape).
3. Return the result: The function returns the list [rows, columns], where rows represents the number of rows and columns represents the number of columns in the DataFrame.
# Complexity
- Time complexity:
**O(1)** β Accessing the shape attribute is a constant-time operation.
- Space complexity:
**O(1)** β Only a single list of size two is created and returned, using negligible extra space.
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 1 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Inbuilt Function || List || 1 Line Solutionππ | inbuilt-function-list-1-line-solution-by-vvoj | IntuitionThe goal of this function is to return the size of the players DataFrame in terms of its number of rows and columns. The shape attribute of a pandas.Da | Vipul_05_Jain | NORMAL | 2025-02-12T06:05:49.330748+00:00 | 2025-02-12T06:05:49.330748+00:00 | 596 | false | # Intuition
The goal of this function is to return the size of the players DataFrame in terms of its number of rows and columns. The shape attribute of a pandas.DataFrame provides a tuple containing the number of rows and columns of the DataFrame.
# Approach
1. Input: The function takes in a pandas.DataFrame called players.
2. Using shape:
* The shape attribute of the DataFrame returns a tuple where:
* The first value represents the number of rows.
* The second value represents the number of columns.
3. Conversion to List:
* The function converts this tuple to a list using list(players.shape).
4. Return:
* The function returns a list with two integers: the number of rows and the number of columns.
# Complexity
- Time complexity: O(1)
- Space complexity: O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 1 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Day 2 | Introduction to Pandas | day-2-introduction-to-pandas-by-x2e22ppn-sku0 | Complexity
Time complexity: O(1)
Space complexity: O(1)
Code | x2e22PPnh5 | NORMAL | 2025-02-11T03:12:19.040462+00:00 | 2025-02-11T03:12:19.040462+00:00 | 284 | false | # Complexity
- Time complexity: O(1)
- Space complexity: O(1)
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
result = [players.shape[0], players.shape[1]]
return result
``` | 1 | 0 | ['Python3', 'Pandas'] | 0 |
get-the-size-of-a-dataframe | ππππππEZPZππππLEMON SQUEEZYππππ PANDAS IS TOO EASY | ezpzlemon-squeezy-pandas-is-too-easy-by-n5m0s | 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 | lallen312 | NORMAL | 2024-11-15T19:57:36.256978+00:00 | 2024-11-15T19:57:36.257021+00:00 | 171 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```pythondata []\nimport pandas as pd\n\ndef getDataframeSize(players: pd.DataFrame) -> List[int]:\n return [players.shape[0], players.shape[1]]\n``` | 1 | 0 | ['Pandas'] | 1 |
get-the-size-of-a-dataframe | Easy solution by using df.shape | easy-solution-by-using-dfshape-by-mshiva-1vlu | Intuition\nWe can use any function to count up the number of rows and columns \n\n# Approach\nuse the dataframe object and apply the shape method to get the siz | mshivanshmaurya | NORMAL | 2024-11-05T04:19:54.393478+00:00 | 2024-11-05T04:19:54.393511+00:00 | 449 | false | # Intuition\nWe can use any function to count up the number of rows and columns \n\n# Approach\nuse the dataframe object and apply the shape method to get the size of the df\n\n# Complexity\n- Time complexity:\no(1)\n\n- Space complexity:\no(1)\n\n# Code\n```pythondata []\nimport pandas as pd\n\ndef getDataframeSize(players: pd.DataFrame) -> List[int]:\n [num_rows,num_col] = players.shape \n return [num_rows , num_col]\n``` | 1 | 0 | ['Pandas'] | 2 |
get-the-size-of-a-dataframe | Most easiest way | most-easiest-way-by-vigneshvaran0101-d1iq | \n\n# Code\n\nimport pandas as pd\n\ndef getDataframeSize(players: pd.DataFrame) -> List[int]:\n row = len(players.axes[0])\n col = len(players.axes[1])\n | vigneshvaran0101 | NORMAL | 2024-07-01T18:19:01.046501+00:00 | 2024-07-01T18:19:01.046534+00:00 | 5 | false | \n\n# Code\n```\nimport pandas as pd\n\ndef getDataframeSize(players: pd.DataFrame) -> List[int]:\n row = len(players.axes[0])\n col = len(players.axes[1])\n return [row, col]\n\n``` | 1 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Solution | solution-by-krupa_20-n0in | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n# Importing libraries\n# defining function name getDataFrames\n# players | 20250324.krupa_20 | NORMAL | 2024-06-02T08:28:12.342184+00:00 | 2024-06-02T08:28:12.342207+00:00 | 2,492 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n# Importing libraries\n# defining function name getDataFrames\n# players takes the argument of dataframe\n# List[int]: - return type\n# axes[0],axes[1] - acessing 1st row and 2nd axis ie. columns\n# en(players.axes[0]),cols = len(players.axes[1]) - calculating no of rows and columns\n# return total number of rows and columns\n \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)$$ -->\n\n# Code\n```\nimport pandas as pd\n\ndef getDataframeSize(players: pd.DataFrame) -> List[int]:\n rows = len(players.axes[0])\n cols = len(players.axes[1])\n return [rows,cols]\n``` | 1 | 0 | ['Pandas'] | 1 |
get-the-size-of-a-dataframe | Size of dataframe in pandas | size-of-dataframe-in-pandas-by-shreyagar-8epf | Code | ShreyaGarg63 | NORMAL | 2024-05-25T09:18:55.168925+00:00 | 2025-01-13T06:25:18.992342+00:00 | 9 | false | # Code
```
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
t = players.shape
l = []
l = list(t)
return l
``` | 1 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Elegant and Short || 1-Liner || Easy to Understand | elegant-and-short-1-liner-easy-to-unders-vxqp | \nimport pandas as pd\ndef getDataframeSize(players: pd.DataFrame) -> List[int]:\n return [players.shape[0], players.shape[1]]\n | YangZen09 | NORMAL | 2024-05-10T05:37:54.493484+00:00 | 2024-05-10T05:37:54.493519+00:00 | 18 | false | ```\nimport pandas as pd\ndef getDataframeSize(players: pd.DataFrame) -> List[int]:\n return [players.shape[0], players.shape[1]]\n``` | 1 | 0 | ['Python', 'Python3'] | 0 |
get-the-size-of-a-dataframe | Pandas Easy Solution π―π₯π₯ | pandas-easy-solution-by-_pandeyad-kssq | \nimport pandas as pd\n\ndef getDataframeSize(players: pd.DataFrame) -> List[int]:\n r,c = players.shape\n return[r,c]\n \n``` | _pandeyad | NORMAL | 2024-01-21T18:11:03.772173+00:00 | 2024-01-21T18:11:03.772207+00:00 | 1,978 | false | \nimport pandas as pd\n\ndef getDataframeSize(players: pd.DataFrame) -> List[int]:\n r,c = players.shape\n return[r,c]\n \n``` | 1 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | [ Pandas ] β
β
Simple Pandas Solution | 3 Approach π₯³βπ | pandas-simple-pandas-solution-3-approach-wzx6 | If You like the Solution, Don\'t Forget To UpVote Me, Please UpVote! \uD83D\uDD3C\uD83D\uDE4F\n# Runtime: 551 ms, faster than 21.63% of Pandas online submission | ashok_kumar_meghvanshi | NORMAL | 2023-12-07T11:53:35.074072+00:00 | 2023-12-19T08:36:18.471489+00:00 | 20 | false | # If You like the Solution, Don\'t Forget To UpVote Me, Please UpVote! \uD83D\uDD3C\uD83D\uDE4F\n# Runtime: 551 ms, faster than 21.63% of Pandas online submissions for Get the Size of a DataFrame.\n# Memory Usage: 60.5 MB, less than 19.56% of Pandas online submissions for Get the Size of a DataFrame.\n\n\timport pandas as pd\n\n\tdef getDataframeSize(players: pd.DataFrame) -> List[int]:\n\t\n\t\treturn [players.shape[0], players.shape[1]]\n\n------------------------------------------------------------------\n\n\timport pandas as pd\n\n\tdef getDataframeSize(players: pd.DataFrame) -> List[int]:\n\n\t\tresult = [len(players) , len(players.columns)]\n\n\t\treturn result\n\t\t\n------------------------------------------------------------------\n\n\timport pandas as pd\n\n\tdef getDataframeSize(players: pd.DataFrame) -> List[int]:\n\t\n\t\tresult = list(players.shape)\n\t\n\t\treturn result\n\n------------------------------------------------------------------\n\n\tTime Complexity : O(1)\n\tSpace Complexity : O(1)\n# Thank You \uD83E\uDD73\u270C\uD83D\uDC4D | 1 | 0 | ['Python', 'Python3'] | 0 |
get-the-size-of-a-dataframe | Easy to understand code || 1-Linear Solution | easy-to-understand-code-1-linear-solutio-j7tt | if you like my effort . Please upvote my solution\n# Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your appro | _kartikapanwar_ | NORMAL | 2023-11-25T10:42:49.804997+00:00 | 2023-11-25T10:42:49.805024+00:00 | 10 | false | if you like my effort . Please upvote my solution\n# 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)$$ -->\n\n# Code\n```\nimport pandas as pd\n\ndef getDataframeSize(players: pd.DataFrame) -> List[int]:\n return list(players.shape)\n``` | 1 | 0 | ['Sorting', 'Python', 'Python3', 'Pandas', 'Python ML'] | 0 |
get-the-size-of-a-dataframe | Getting the size of a DF and returning it as a list | getting-the-size-of-a-df-and-returning-i-e00s | Code | RobaireTH | NORMAL | 2025-04-11T00:29:59.631958+00:00 | 2025-04-11T00:29:59.631958+00:00 | 1 | false |
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame):
return list(players.shape)
#This will return [number_of_rows, number_of_cols]
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Solution!!! | solution-by-bhas7jnmth-6qc2 | IntuitionRead description carefullyApproachComplexity
Time complexity
Space complexity:
Code | bhas7JNmth | NORMAL | 2025-04-10T22:17:42.147396+00:00 | 2025-04-10T22:17:42.147396+00:00 | 1 | false | # Intuition
Read description carefully
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | my solution | my-solution-by-ranimrebai-0spf | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | RanimRebai | NORMAL | 2025-04-10T12:38:23.488966+00:00 | 2025-04-10T12:38:23.488966+00:00 | 1 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
tp=players.shape
l=list()
l.append(tp[0])
l.append(tp[1])
return l
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Get the size of a DataFrame | get-the-size-of-a-dataframe-by-rajshivam-je43 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | rajshivam352 | NORMAL | 2025-04-06T14:34:22.470178+00:00 | 2025-04-06T14:34:22.470178+00:00 | 1 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return [*players.shape]
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Pandas lesson 2 | pandas-lesson-2-by-titouanm-dqch | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | titouanm | NORMAL | 2025-04-03T06:13:42.522687+00:00 | 2025-04-03T06:13:42.522687+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return [len(players), len(players.columns)]
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | get the size of a dataframe | get-the-size-of-a-dataframe-by-d8750-t7xm | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | d8750 | NORMAL | 2025-04-01T17:40:23.386906+00:00 | 2025-04-01T17:40:23.386906+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
from typing import List
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return [players.shape[0], players.shape[1]]
players = {
'player_id': [849,749,155,583,388,883,355,247,761, 642],
'name': ['mason','riley','bob','isabella','zachery','ava','violet','thomas','jack','charlie'],
'age': [21,30,28,32,24,23,18,27,33,36],
'position': ['fowward','winger','striker','goalkeeper','midfielder','defender','striker','striker','midfielder','center-back']
}
df = getDataFrame(players)
size = getDataFramesize(df)
print(size)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Day2 | day2-by-ingridtseng-dmoe | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | ingridtseng | NORMAL | 2025-04-01T14:58:28.354384+00:00 | 2025-04-01T14:58:28.354384+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
row, col = players.shape
shape = [row, col]
return shape
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | 1 Line solution | 1-line-solution-by-durga_raju-c572 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | durga_raju | NORMAL | 2025-04-01T11:21:12.930822+00:00 | 2025-04-01T11:21:12.930822+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Simple solution that beats 95.13% of users. | simple-solution-that-beats-9513-of-users-pfjt | IntuitionThe problem asks us to get the total numbers of rows and columns as an array. At first I tried using the DataFrame.size method but it returns the total | MstMhb8Ly5 | NORMAL | 2025-03-31T20:36:06.230578+00:00 | 2025-03-31T20:36:06.230578+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem asks us to get the total numbers of rows and columns as an array. At first I tried using the `DataFrame.size` method but it returns the total number of columns * rows. But that isn't what we want. Instead I did this
# Approach
<!-- Describe your approach to solving the problem. -->
I decided to use the `DataFrame.shape` method which returns the number of rows and columns in a tuple, and to convert it into a list/array I used the `list()` method
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Simple Pandas Solution | simple-pandas-solution-by-gokulram2221-1z0j | Code | gokulram2221 | NORMAL | 2025-03-31T04:50:49.437963+00:00 | 2025-03-31T04:50:49.437963+00:00 | 4 | false | # Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List:
return [players.shape[0], players.shape[1]]
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Super-Easy Python Solution | Beginner Friendly | super-easy-python-solution-beginner-frie-in6f | Code | rajsekhar5161 | NORMAL | 2025-03-30T05:17:55.395745+00:00 | 2025-03-30T05:17:55.395745+00:00 | 3 | false |
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
df=pd.DataFrame(players)
return [players.shape[0],players.shape[1]]
``` | 0 | 0 | ['Array', 'Python', 'Python3', 'Pandas'] | 0 |
get-the-size-of-a-dataframe | Super Easy Python Solution | Using attributes of Pandas | super-easy-python-solution-using-attribu-gh4t | Code | rajsekhar5161 | NORMAL | 2025-03-29T19:48:32.634116+00:00 | 2025-03-29T19:48:32.634116+00:00 | 3 | false |
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
df=pd.DataFrame(players)
return [players.shape[0],players.shape[1]]
``` | 0 | 0 | ['Array', 'Database', 'Python', 'Python3', 'Pandas'] | 0 |
get-the-size-of-a-dataframe | Simple approach , Beats 90% | simple-approach-beats-90-by-jigneshvyas-8jp1 | IntuitionApproachRetrive shape and create listComplexity
Time complexity:
Space complexity:
Code | jigneshvyas | NORMAL | 2025-03-27T04:38:26.683465+00:00 | 2025-03-27T04:38:26.683465+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
Retrive shape and create list
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return [players.shape[0],players.shape[1]]
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Python Solution | python-solution-by-ikfb47ngox-0lou | IntuitionUse the built-in PandasApproachUse the df.shape function and return the result as a listComplexity
Time complexity:
O(n) to iterate through the list
Sp | ikFB47NGox | NORMAL | 2025-03-26T18:01:48.356260+00:00 | 2025-03-26T18:01:48.356260+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Use the built-in Pandas
# Approach
<!-- Describe your approach to solving the problem. -->
Use the df.shape function and return the result as a list
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(n) to iterate through the list
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(1) for for the list created
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
result = list(players.shape)
return result
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Easy and simple solution | easy-and-simple-solution-by-ulrichwolves-7a77 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | ulrichwolves | NORMAL | 2025-03-26T14:01:30.621634+00:00 | 2025-03-26T14:01:30.621634+00:00 | 1 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Easy and simple solution | easy-and-simple-solution-by-ulrichwolves-c5ss | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | ulrichwolves | NORMAL | 2025-03-26T14:01:26.894604+00:00 | 2025-03-26T14:01:26.894604+00:00 | 1 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Solution | solution-by-krupadharamshi-a3ak | Code | KrupaDharamshi | NORMAL | 2025-03-26T09:56:49.515760+00:00 | 2025-03-26T09:56:49.515760+00:00 | 2 | false |
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | size of DataFrame | size-of-dataframe-by-kittur_manjunath-vc16 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | kittur_manjunath | NORMAL | 2025-03-26T09:24:14.628972+00:00 | 2025-03-26T09:24:14.628972+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return [players.shape[0],players.shape[1]]
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Get the Size of a DataFrame | get-the-size-of-a-dataframe-by-shalinipa-sypr | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | ShaliniPaidimuddala | NORMAL | 2025-03-24T08:16:22.993876+00:00 | 2025-03-24T08:16:22.993876+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
lst=[players.index.size,players.columns.size]
return lst
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | 1_day_ getDataframeSize | 1_day_-getdataframesize-by-alinaqwertyui-ry65 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | alinaqwertyuiop | NORMAL | 2025-03-23T00:39:10.050374+00:00 | 2025-03-23T00:39:10.050374+00:00 | 1 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
rows, columns = players.shape
return [rows, columns]
data = {
'player_id': [1, 2, 3, 4, 5],
'name': ['Alice', 'Bob', 'Charlie', 'David', 'Eve'],
'age': [25, 30, 22, 28, 24]
}
players = pd.DataFrame(data)
size = getDataframeSize(players)
print(size)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Get The Size of a DataFrame | get-the-size-of-a-dataframe-by-naeem_abd-v890 | IntuitionApproachComplexityTime complexity: O(1)
Space complexity: O(1)Code | Naeem_ABD | NORMAL | 2025-03-21T15:30:26.529922+00:00 | 2025-03-21T15:30:26.529922+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
Time complexity: O(1)
Space complexity: O(1)
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
result = [players.shape[0], players.shape[1]]
return result
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Get the Size of a DataFrame | get-the-size-of-a-dataframe-by-qpajdvi7x-dt8l | Code | QPaJdvI7XA | NORMAL | 2025-03-21T11:03:57.000661+00:00 | 2025-03-21T11:03:57.000661+00:00 | 3 | false | # Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
rows, columns = pd.DataFrame(players).shape
return [rows, columns]
``` | 0 | 0 | ['Python3', 'Pandas'] | 0 |
get-the-size-of-a-dataframe | Pandas must have function | pandas-must-have-function-by-iazinschi20-bzof | Code | iazinschi2005 | NORMAL | 2025-03-20T23:25:52.045962+00:00 | 2025-03-20T23:25:52.045962+00:00 | 1 | false |
``` bash
-> pandas.DataFrame.shape
property DataFrame.shape[source]
Return a tuple representing the dimensionality of the DataFrame.
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4],
... 'col3': [5, 6]})
>>> df.shape
(2, 3)
```
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | EASY PANDAS SOLUTION (Beats 81.45%) | easy-pandas-solution-beats-8145-by-kahka-iac8 | Code | kahkasha_D | NORMAL | 2025-03-18T17:44:59.083772+00:00 | 2025-03-18T17:44:59.083772+00:00 | 3 | false |
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | python easy | python-easy-by-macha_pratisha-t214 | Code | macha_pratisha | NORMAL | 2025-03-15T16:32:03.777758+00:00 | 2025-03-15T16:32:03.777758+00:00 | 1 | false |
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Efficiently Determining the Size of a Pandas DataFrame Using .shape | efficiently-determining-the-size-of-a-pa-h4we | IntuitionWe need to determine the size (number of rows and columns) of a given pandas DataFrame.
Pandas provides a built-in attribute .shape that returns a tupl | user2791Eu | NORMAL | 2025-03-14T16:16:17.847620+00:00 | 2025-03-14T16:16:17.847620+00:00 | 2 | false | # Intuition
We need to determine the size (number of rows and columns) of a given pandas DataFrame.
Pandas provides a built-in attribute .shape that returns a tuple (num_rows, num_columns).
Since the expected output is a list, we convert the tuple to a list.
# Approach
1) Use players.shape to retrieve the DataFrame dimensions.
2) Convert the tuple (rows, columns) β list using list().
3) Return the list [num_rows, num_columns].
Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Pandas - 2 | pandas-2-by-livmrqs-vozp | ProblemWrite a solution to calculate and display the number of rows and columns of players.Return the result as an array:[number of rows, number of columns]Code | livmrqs_ | NORMAL | 2025-03-12T19:08:42.869389+00:00 | 2025-03-12T19:08:42.869389+00:00 | 2 | false | # Problem
Write a solution to calculate and display the number of rows and columns of players.
Return the result as an array:
[number of rows, number of columns]
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Beginner friendly solution | beginner-friendly-solution-by-gajal_garg-fn7a | ApproachThe .shape attribute in pandas returns the number of rows and columns in a DataFrame as a tuple (rows, columns). But here we've manually converted it in | Gajal_garg | NORMAL | 2025-03-12T10:12:11.764758+00:00 | 2025-03-12T10:12:11.764758+00:00 | 2 | false | # Approach
<!-- Describe your approach to solving the problem. -->
The .shape attribute in pandas returns the number of rows and columns in a DataFrame as a tuple (rows, columns). But here we've manually converted it into a list.
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Get the Size of a DataFrame | get-the-size-of-a-dataframe-by-i3twd28w8-fy45 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | I3Twd28W8N | NORMAL | 2025-03-11T05:02:22.239587+00:00 | 2025-03-11T05:02:22.239587+00:00 | 1 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def createDataframe(student_data):
# Define column names
columns = ["student_id", "age"]
# Create the DataFrame
df = pd.DataFrame(student_data, columns=columns)
return df
def getDataframeSize(df):
return list(df.shape)
# Example input
player_data = [
[846, "Mason", 21, "Forward", "RealMadrid"],
[749, "Riley", 30, "Winger", "Barcelona"],
[155, "Bob", 28, "Striker", "ManchesterUnited"],
[583, "Isabella", 32, "Goalkeeper", "Liverpool"],
[388, "Zachary", 24, "Midfielder", "BayernMunich"],
[883, "Ava", 23, "Defender", "Chelsea"],
[355, "Violet", 18, "Striker", "Juventus"],
[247, "Thomas", 27, "Striker", "ParisSaint-Germain"],
[761, "Jack", 33, "Midfielder", "ManchesterCity"],
[642, "Charlie", 36, "Center-back", "Arsenal"]
]
# Create the DataFrame for players
columns = ["player_id", "name", "age", "position", "team"]
players_df = pd.DataFrame(player_data, columns=columns)
# Get and print the shape
print(getDataframeSize(players_df))
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | getDataframeSize | getdataframesize-by-mettaleb-z18d | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | mettaleb | NORMAL | 2025-03-09T12:19:27.421236+00:00 | 2025-03-09T12:19:27.421236+00:00 | 1 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Pandas #2 | pandas-2-by-tobyb789-3vpr | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | TobyB789 | NORMAL | 2025-03-07T21:10:40.979861+00:00 | 2025-03-07T21:10:40.979861+00:00 | 3 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
#calculate number of rows and columns
#we already know that players is a dataframe
#return the result as an array
def getDataframeSize(players: pd.DataFrame) -> List[int]:
Rows , Columns = players.shape
return [ Rows, Columns ]
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Get the Size of a DataFrame - Introduction to Pandas | get-the-size-of-a-dataframe-introduction-ee4o | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | AleksanderP | NORMAL | 2025-03-02T06:13:41.453934+00:00 | 2025-03-02T06:13:41.453934+00:00 | 1 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Simple and quick solution | simple-and-quick-solution-by-rasikapandi-eeet | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | rasikapandit33 | NORMAL | 2025-03-01T15:46:35.132860+00:00 | 2025-03-01T15:46:35.132860+00:00 | 1 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | soln | soln-by-mr_garg-0g8a | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Mr_garg | NORMAL | 2025-03-01T06:40:25.462354+00:00 | 2025-03-01T06:40:25.462354+00:00 | 1 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | one liner using shape | one-liner-using-shape-by-teja_puramshett-88pj | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Teja_puramshetti | NORMAL | 2025-02-26T10:17:54.003062+00:00 | 2025-02-26T10:17:54.003062+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | π Python3: Get DataFrame Dimensions | 85.78% Runtime | python3-get-dataframe-dimensions-8578-ru-uf9x | IntuitionThe task requires finding the dimensions of a DataFrame - specifically the number of rows and columns. In pandas, this is a basic operation using the l | namebogsecret | NORMAL | 2025-02-23T04:16:13.281855+00:00 | 2025-02-23T04:16:13.281855+00:00 | 4 | false | # Intuition
The task requires finding the dimensions of a DataFrame - specifically the number of rows and columns. In pandas, this is a basic operation using the length of the DataFrame and its columns attribute.
# Approach
1. Get number of rows using `len()` on the DataFrame itself
2. Get number of columns using `len()` on the DataFrame's columns
3. Return both values in a list where:
- First element is number of rows
- Second element is number of columns
# Complexity
- Time complexity: O(1) since we're just accessing DataFrame metadata attributes
- Space complexity: O(1) as we only create a small list with two integers
# Code
```python3 []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return [len(players), len(players.columns)]
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Get the Size of a DataFrame in Pandas very easy solution | get-the-size-of-a-dataframe-in-pandas-ve-r0v6 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Tushar_1920 | NORMAL | 2025-02-22T04:51:48.275761+00:00 | 2025-02-22T04:51:48.275761+00:00 | 3 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List:
return [players.shape[0], players.shape[1]]
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Get the size of a DataFrame - Simple solution that beats 99.09% others | get-the-size-of-a-dataframe-simple-solut-jjyj | Intuitionwe need the shape of given input as a list.Approachwe take the shape of dataframe players which provides a tuple and then return this shape within a li | BadSkull | NORMAL | 2025-02-20T20:38:45.012706+00:00 | 2025-02-20T20:38:45.012706+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
we need the shape of given input as a list.
# Approach
<!-- Describe your approach to solving the problem. -->
we take the shape of dataframe players which provides a tuple and then return this shape within a list.
# Complexity
- Time complexity:O(1)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | My 16th Problem (pd) | my-16th-problem-pd-by-chefcurry4-7f70 | ApproachSimply use pd.Dataframe.shape keeping in mind that this gives a tuple.Complexity
Time complexity:O(1)-> Retrieving the shape of a DataFrame is a constan | Chefcurry4 | NORMAL | 2025-02-19T23:54:38.323707+00:00 | 2025-02-19T23:54:38.323707+00:00 | 2 | false | # Approach
<!-- Describe your approach to solving the problem. -->
Simply use pd.Dataframe.shape keeping in mind that this gives a tuple.
# Complexity
- Time complexity: $$O(1)$$ -> Retrieving the shape of a DataFrame is a constant-time operation.
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: $$O(1)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | beginner-friendly! ππ | beginner-friendly-by-latha_dande-94nt | Approachshape attribute gives us Number of rows and Number of columns in tuple format.Example:(10,5)By using typecasting technique I convert tuple to list by us | Latha_Dande | NORMAL | 2025-02-19T17:39:30.966194+00:00 | 2025-02-19T17:39:30.966194+00:00 | 0 | false | # Approach
shape attribute gives us Number of rows and Number of columns in tuple format.
Example:(10,5)
Here 10 denotes Number of rows in DataFrame
Here 5 denotes Number of Number of columns
By using typecasting technique I convert tuple to list by using list() function.
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | beginner-friendly! ππ | beginner-friendly-by-latha_dande-p0kz | Approachshape attribute gives us Number of rows and Number of columns in tuple format.Example:(10,5)By using typecasting technique I convert tuple to list by us | Latha_Dande | NORMAL | 2025-02-19T17:39:21.434941+00:00 | 2025-02-19T17:39:21.434941+00:00 | 1 | false | # Approach
shape attribute gives us Number of rows and Number of columns in tuple format.
Example:(10,5)
Here 10 denotes Number of rows in DataFrame
Here 5 denotes Number of Number of columns
By using typecasting technique I convert tuple to list by using list() function.
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Avoid this degeneracy | avoid-this-degeneracy-by-smallsonxdd-u256 | Code | SmallSonxdd | NORMAL | 2025-02-19T06:25:20.072089+00:00 | 2025-02-19T06:25:20.072089+00:00 | 2 | false | # Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
indexes = len(players.values)
columns = (players.size//indexes)
return [indexes, columns]
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Get the Size of a DataFrame: Beginner Frinedly Code | get-the-size-of-a-dataframe-beginner-fri-eygn | IntuitionThe problem requires finding the number of rows and columns in a given DataFrame. Since pandas provides a built-in method .shape that returns a tuple ( | jruzz_1567 | NORMAL | 2025-02-18T19:25:51.021325+00:00 | 2025-02-18T19:25:51.021325+00:00 | 2 | false | # Intuition
The problem requires finding the number of rows and columns in a given DataFrame. Since pandas provides a built-in method .shape that returns a tuple (num_rows, num_columns), we can directly use it to extract the required information.
# Approach
1. Understanding the Input: The input is a pandas DataFrame containing multiple columns such as player_id, name, age, position, and more.
2. Using .shape: The .shape attribute of a DataFrame returns a tuple (rows, columns), where:
- The first element represents the number of rows.
- The second element represents the number of columns.
3. Returning as a List: Since the problem asks for an array (list in Python), we convert the tuple to a list using list(players.shape).
# Complexity
- Time Complexity: O(1)
Accessing .shape is a constant-time operation since it does not require iterating over the DataFrame.
- Space Complexity: O(1)
We are only returning a two-element list without additional memory allocation.
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Python one liner solution | python-one-liner-solution-by-swanand_jos-o727 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Swanand_Joshi | NORMAL | 2025-02-17T17:11:01.016762+00:00 | 2025-02-17T17:11:01.016762+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | DAY-2 | Pandas | Size of Data Frame | day-2-pandas-size-of-data-frame-by-nidhi-ehwb | ApproachUse built-in function
shape
Complexity
Time complexity: O(1)
Space complexity: O(1)
Code | Nidhi_Kamal | NORMAL | 2025-02-16T10:44:21.054376+00:00 | 2025-02-16T10:44:21.054376+00:00 | 1 | false | # Approach
Use built-in function
- shape
# Complexity
- Time complexity: O(1)
- Space complexity: O(1)
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return [players.shape[0], players.shape[1]]
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Fast & Memory efficient way to get the shape in list format | fast-memory-efficient-way-to-get-the-sha-6646 | Code | natashaa027 | NORMAL | 2025-02-15T08:30:20.180816+00:00 | 2025-02-15T08:30:20.180816+00:00 | 1 | false | # Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(i for i in players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Printing-out the shape | printing-out-the-shape-by-abdoulfatah-55ax | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Abdoulfatah | NORMAL | 2025-02-14T08:00:13.872767+00:00 | 2025-02-14T08:00:13.872767+00:00 | 2 | false | # Intuition
<!-- My first thought was to use .shape attributes. -->
# Approach
<!-- Since .shape is outputing rows and cols tuple, so i converted to a list in order to follow the requirements -->
# Complexity
- Time complexity:
<!-- O(1) -> is constant because its printing two values-->
- Space complexity:
<!-- o(1) it's only stored two values-->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Use shape variable of Dataframe | use-shape-variable-of-dataframe-by-alokk-5jza | IntuitionUse shape variable of DataframeApproachComplexity
Time complexity:
Space complexity:
Code | alokku1290 | NORMAL | 2025-02-12T09:21:27.462594+00:00 | 2025-02-12T09:21:27.462594+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Use shape variable of Dataframe
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return [ players.shape[0], players.shape[1] ]
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | β
Easy And Simple Solution With EXPLANATIONβ
| easy-and-simple-solution-with-explanatio-4gei | IntuitionGiven a DataFrame players, we need to determine the number of rows and columns. This can be done by utilizing the DataFrame's axes attribute, which pro | A_nishkumar | NORMAL | 2025-02-11T14:31:20.896849+00:00 | 2025-02-11T14:31:20.896849+00:00 | 3 | false | # Intuition
Given a DataFrame players, we need to determine the number of rows and columns. This can be done by utilizing the DataFrame's axes attribute, which provides access to the row and column labels.
# Approach
1. **Importing the Required Library:** We first need to import the pandas library, which is a powerful tool in Python for data manipulation and analysis.
2. **Defining the function:** This line defines a new function named getDataframeSize which takes a DataFrame players as an input argument and returns a list that contains the number of rows and columns in the DataFrame players.
3. **Using the shape attribute:** Every DataFrame in pandas has a shape attribute. When you call it, it returns a tuple (number of rows, number of columns). In our case, for the given players DataFrame, the shape would be (10, 5) because there are 10 players and 5 attributes for each player.
# Complexity
- Time complexity: O(1) - The operations to get the lengths of the axes are constant time operations.
- Space complexity: O(1) - No additional space is used other than a few variables for storing the lengths.
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return [players.shape[0],players.shape[1]]
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Single return statement | single-return-statement-by-juergenpfau-gimr | IntuitionDF object should probably have these characteristicsApproachpandas.pydata attributesComplexity
Time complexity:
Space complexity:
Code | Juergenpfau | NORMAL | 2025-02-05T04:12:42.214727+00:00 | 2025-02-05T04:12:42.214727+00:00 | 3 | false | # Intuition
DF object should probably have these characteristics
# Approach
pandas.pydata attributes
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return [players.index.size, players.columns.size]
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | you can try your luck here_=_ | you-can-try-your-luck-here__-by-rao1-ws6e | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Sathwik_rao3 | NORMAL | 2025-02-04T09:45:13.401631+00:00 | 2025-02-04T09:45:13.401631+00:00 | 3 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
[r,c]=players.shape
return [r,c]
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | one command one line | one-command-one-line-by-ludentrop-96hd | Approachit was the first thoughtComplexity
Time complexity:
O(1)
Space complexity:
O(1)
Code | Ludentrop | NORMAL | 2025-01-28T21:17:15.608677+00:00 | 2025-01-28T21:17:15.608677+00:00 | 5 | false | # Approach
it was the first thought
# Complexity
- Time complexity:
$$O(1)$$
- Space complexity:
$$O(1)$$
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Intro to Pandas Q2 | intro-to-pandas-q2-by-jcharnleydata-hk4b | Code | JCharnleyData | NORMAL | 2025-01-27T19:19:33.202743+00:00 | 2025-01-27T19:19:33.202743+00:00 | 2 | false | # Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return [players.shape[0],players.shape[1]]
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Number of rows and columns | number-of-rows-and-columns-by-pratyushda-ncmf | Intuition
Understanding the problem: Determine the need to find the dimensions of the DataFrame.
Key focus: Use a simple and efficient way to retrieve the size | PratyushDas | NORMAL | 2025-01-27T10:01:14.918083+00:00 | 2025-01-27T10:01:14.918083+00:00 | 2 | false | ## Intuition
- **Understanding the problem**: Determine the need to find the dimensions of the DataFrame.
- **Key focus**: Use a simple and efficient way to retrieve the size of the DataFrame.
## Approach
- **Library import**: Import the required pandas library.
- **Function definition**: Define the function `getDataframeSize` which takes a DataFrame as input.
- **Retrieve dimensions**: Use the `shape` attribute of the DataFrame to get the number of rows and columns.
- **Return the result**: Return the dimensions as a list.
## Complexity
- **Time complexity**:
- The operation to get the shape of the DataFrame is `O(1)`, as it directly accesses the metadata.
- **Space complexity**:
- The space complexity is also `O(1)`, as the operation does not use additional space beyond storing the dimensions.
## Code
```python
import pandas as pd
from typing import List
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return [players.shape[0], players.shape[1]]
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | simple one string | simple-one-string-by-olegbourdo-a2u0 | Intuitionuse shapeApproachreturn the shape method converted to the listCode | OlegBourdo | NORMAL | 2025-01-27T08:13:15.844257+00:00 | 2025-01-27T08:13:15.844257+00:00 | 2 | false | # Intuition
use shape
# Approach
return the shape method converted to the list
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | BEST SOLUTION | best-solution-by-rhyd3dxa6x-3vak | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | rhyD3DxA6x | NORMAL | 2025-01-24T11:48:28.298102+00:00 | 2025-01-24T11:48:28.298102+00:00 | 3 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Get DataFrame Size as list | get-dataframe-size-as-list-by-pinkmaggs-im8e | IntuitionThe DataFrame.shape attribute provides the dimensions of the DataFrame as a tuple, with the number of rows and columns. Since we need a list containing | pinkmaggs | NORMAL | 2025-01-22T21:27:34.069669+00:00 | 2025-01-22T21:27:34.069669+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The DataFrame.shape attribute provides the dimensions of the DataFrame as a tuple, with the number of rows and columns. Since we need a list containing these dimensions, we can simply convert the tuple into a list using a one-liner. Given that the tuple always has a fixed size of 2 (rows and columns), the time and space complexity is constant.
# Approach
<!-- Describe your approach to solving the problem. -->
Access the shape attribute of the DataFrame, which returns a tuple (number_of_rows, number_of_columns). Then convert the tuple into a list by iterating over the tuple. Return the list.
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(1)
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(1)
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return [i for i in players.shape]
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | One line solution | one-line-solution-by-prettywired-3rsu | IntuitionWe needed only the number of rows and columns.ApproachSince we can access rows via .index and columns via .columns from pd dataframes, we apply len() f | Prettywired | NORMAL | 2025-01-21T07:36:25.503912+00:00 | 2025-01-21T07:36:25.503912+00:00 | 6 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
We needed only the number of rows and columns.
# Approach
<!-- Describe your approach to solving the problem. -->
Since we can access rows via .index and columns via .columns from pd dataframes, we apply len() function to see how many there are.
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return [len(players.index),len(players.columns)]
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Python_Easy | python_easy-by-prabhat7667-sw3p | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | prabhat7667 | NORMAL | 2025-01-18T12:33:23.245835+00:00 | 2025-01-18T12:33:23.245835+00:00 | 6 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
rows,cols = players.shape
p = [rows,cols]
return p
``` | 0 | 0 | ['Pandas'] | 0 |
get-the-size-of-a-dataframe | Get the Size of the DataFrame | get-the-size-of-the-dataframe-by-reneema-87au | IntuitionTo finding the solution to calculating the number of rows and columns of the given table playersApproachComplexity
Time complexity:
483ms
Beats 32.73% | ReneeMatthew | NORMAL | 2025-01-17T03:05:45.851295+00:00 | 2025-01-17T03:05:45.851295+00:00 | 5 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
To finding the solution to calculating the number of rows and columns of the given table players
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
<i>483ms
Beats 32.73%</i>
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
<i>66.00 MB
Beats 41.46%</i>
# Code
```pythondata []
import pandas as pd
def getDataframeSize(players: pd.DataFrame) -> List[int]:
return list(players.shape)
``` | 0 | 0 | ['Pandas'] | 0 |
adding-two-negabinary-numbers | [C++/Python] Convert from Base 2 Addition | cpython-convert-from-base-2-addition-by-40ngy | Intuition:\nQuite similar to 1017. Convert to Base -2\n1. Maybe write a base2 addition first?\n2. Add minus -?\n3. Done.\n\n\n\n## Complexity\nTime O(N), Space | lee215 | NORMAL | 2019-06-02T04:03:44.923373+00:00 | 2019-06-02T04:03:44.923416+00:00 | 12,530 | false | ## **Intuition**:\nQuite similar to [1017. Convert to Base -2](https://leetcode.com/problems/convert-to-base-2/discuss/265507/JavaC++Python-2-lines-Exactly-Same-as-Base-2)\n1. Maybe write a base2 addition first?\n2. Add minus `-`?\n3. Done.\n<br>\n\n\n## **Complexity**\nTime `O(N)`, Space `O(N)`\n<br>\n\n\n**C++:**\n```\n vector<int> addBinary(vector<int>& A, vector<int>& B) {\n vector<int> res;\n int carry = 0, i = A.size() - 1, j = B.size() - 1;\n while (i >= 0 || j >= 0 || carry) {\n if (i >= 0) carry += A[i--];\n if (j >= 0) carry += B[j--];\n res.push_back(carry & 1);\n carry = (carry >> 1);\n }\n reverse(res.begin(), res.end());\n return res;\n }\n\n vector<int> addNegabinary(vector<int>& A, vector<int>& B) {\n vector<int> res;\n int carry = 0, i = A.size() - 1, j = B.size() - 1;\n while (i >= 0 || j >= 0 || carry) {\n if (i >= 0) carry += A[i--];\n if (j >= 0) carry += B[j--];\n res.push_back(carry & 1);\n carry = -(carry >> 1);\n }\n while (res.size() > 1 && res.back() == 0)\n res.pop_back();\n reverse(res.begin(), res.end());\n return res;\n }\n```\n\n**Python:**\n```\n def addBinary(self, A, B):\n res = []\n carry = 0\n while A or B or carry:\n carry += (A or [0]).pop() + (B or [0]).pop()\n res.append(carry & 1)\n carry = carry >> 1\n return res[::-1]\n\n def addNegabinary(self, A, B):\n res = []\n carry = 0\n while A or B or carry:\n carry += (A or [0]).pop() + (B or [0]).pop()\n res.append(carry & 1)\n carry = -(carry >> 1)\n while len(res) > 1 and res[-1] == 0:\n res.pop()\n return res[::-1]\n```\n | 116 | 3 | [] | 15 |
adding-two-negabinary-numbers | C++ From Wikipedia | c-from-wikipedia-by-votrubac-1jgk | See Wikipedia\'s Negative Base Addition.\n\nWe start from the least signifficant bit, and do the binary summation as usual. However, our carry can have three st | votrubac | NORMAL | 2019-06-02T04:18:25.620853+00:00 | 2019-06-02T04:41:40.735327+00:00 | 5,193 | false | See [Wikipedia\'s Negative Base Addition](https://en.wikipedia.org/wiki/Negative_base#Addition).\n\nWe start from the least signifficant bit, and do the binary summation as usual. However, our carry can have three states: -1, 0, and 1.\n\nIf the sum for the current bit is greater than 2, the carry becomes -1, not 1 as in the base 2 case. Because of that, our sum can become -1. In this case, the carry should be set to 1.\n```\nvector<int> addNegabinary(vector<int>& a1, vector<int>& a2) {\n vector<int> res;\n int bit = 0, carry = 0, sz = max(a1.size(), a2.size());\n for (auto bit = 0; bit < sz || carry != 0; ++bit) {\n auto b1 = bit < a1.size() ? a1[a1.size() - bit - 1] : 0;\n auto b2 = bit < a2.size() ? a2[a2.size() - bit - 1] : 0;\n auto sum = b1 + b2 + carry;\n res.push_back(abs(sum) % 2); \n carry = sum < 0 ? 1 : sum > 1 ? -1 : 0;\n }\n while (res.size() > 1 && res.back() == 0) res.pop_back();\n reverse(begin(res), end(res));\n return res;\n}\n``` | 43 | 2 | [] | 2 |
adding-two-negabinary-numbers | [Python beats 100%]This is my first question I contributed on leetcode, here is my approach | python-beats-100this-is-my-first-questio-nha3 | I was asked during an interview and I found that it was quite interesting so I contributed it here.\n\nActually, during the interview, my intuition was to trans | calvinchankf | NORMAL | 2019-06-02T06:17:32.916825+00:00 | 2019-06-02T06:17:32.916892+00:00 | 3,595 | false | I was asked during an interview and I found that it was quite interesting so I contributed it here.\n\nActually, during the interview, my intuition was to transform the arr1 and arr2 to numbers and add and transform it back to a negabinary number using the way like #1017. \n\nBut later I found out from the [wikipedia](https://en.wikipedia.org/wiki/Negative_base#Addition) that there is a much better way.\n\n```py\nclass Solution(object):\n def addNegabinary(self, arr1, arr2):\n """\n ref:\n - https://en.wikipedia.org/wiki/Negative_base#Addition\n\n Carry: 1 \u22121 0 \u22121 1 \u22121 0 0 0\n First addend: 1 0 1 0 1 0 1\n Second addend: 1 1 1 0 1 0 0 + addition\n --------------------------\n Number: 1 \u22121 2 0 3 \u22121 2 0 1 when we come with a number, lookup from the hashtable\n -----------------------------------------\n Bit (result): 1 1 0 0 1 1 0 0 1\n Carry: 0 1 \u22121 0 \u22121 1 \u22121 0 0 <- each number will be moved to the carry on the top in the next bit\n """\n lookup = {\n -2: (0, 1), # useless becos \u22122 occurs only during subtraction\n -1: (1, 1),\n 0: (0, 0),\n 1: (1, 0),\n 2: (0, -1),\n 3: (1, -1),\n }\n carry = 0\n result = []\n # do addition\n while len(arr1) > 0 or len(arr2) > 0:\n a = 0\n if len(arr1) > 0:\n a = arr1.pop()\n b = 0\n if len(arr2) > 0:\n b = arr2.pop()\n temp = a + b + carry\n res, carry = lookup[temp]\n result.append(res)\n # if there is still a carry\n while carry != 0:\n res, carry = lookup[carry]\n result.append(res)\n # remove leading zeros\n while len(result) > 1 and result[-1] == 0:\n result.pop()\n return result[::-1]\n```\n\nHonestly, I don\'t think I can come up with this. But now I see there are some better approaches, so thank you everyone.\n- [from @lee215](https://leetcode.com/problems/adding-two-negabinary-numbers/discuss/303751/C%2B%2BPython-Convert-from-Base-2-Addition)\n- [from @tiankonguse](https://leetcode.com/problems/adding-two-negabinary-numbers/discuss/303831/ChineseC%2B%2B-1073)\n- [from @litian220](https://leetcode.com/problems/adding-two-negabinary-numbers/discuss/303809/Java-Use-stack-Beat-100)\n- [from @amitnsky](https://leetcode.com/problems/adding-two-negabinary-numbers/discuss/303875/Adjust-or-Carry-method)\n- [from @bupt_wc](https://leetcode.com/problems/convert-to-base-2/discuss/265688/4-line-python-clear-solution-with-explanation) | 22 | 1 | [] | 6 |
adding-two-negabinary-numbers | Java Use stack Beat 100% | java-use-stack-beat-100-by-sky_way-hzvk | \nclass Solution {\n public int[] addNegabinary(int[] arr1, int[] arr2) {\n int i = arr1.length - 1, j = arr2.length - 1, carry = 0;\n Stack<In | sky_way | NORMAL | 2019-06-02T04:27:11.896426+00:00 | 2019-06-02T04:27:11.896482+00:00 | 2,504 | false | ```\nclass Solution {\n public int[] addNegabinary(int[] arr1, int[] arr2) {\n int i = arr1.length - 1, j = arr2.length - 1, carry = 0;\n Stack<Integer> stack = new Stack<>();\n while (i >= 0 || j >= 0 || carry != 0) {\n int v1 = i >= 0 ? arr1[i--] : 0;\n int v2 = j >= 0 ? arr2[j--] : 0;\n carry = v1 + v2 + carry;\n stack.push(carry & 1);\n carry = -(carry >> 1);\n }\n while (!stack.isEmpty() && stack.peek() == 0) stack.pop();\n int[] res = new int[stack.size()];\n int index = 0;\n while (!stack.isEmpty()) {\n res[index++] = stack.pop();\n }\n return res.length == 0 ? new int[1] : res;\n }\n}\n``` | 12 | 2 | [] | 4 |
adding-two-negabinary-numbers | [Python3] Solved with maths | python3-solved-with-maths-by-skasch-e6gm | I wrote down the maths to compute the addition. Here are my findings:\n\nThe main issue is when we add two "ones" at the same position. How do we carry the rema | skasch | NORMAL | 2020-07-12T05:59:18.389342+00:00 | 2020-07-12T06:02:29.435079+00:00 | 1,302 | false | I wrote down the maths to compute the addition. Here are my findings:\n\nThe main issue is when we add two "ones" at the same position. How do we carry the remainder to the next position? Let us write down the maths. Let us consider our numbers\n\n```\na = sum a_i * (-2)^i\nb = sum b_i * (-2)^i\n```\n\nLet us consider a position `i` such that `a_i` and `b_i` are both equal to 1. In that case:\n\n```\na_i * (-2)^i + b_i * (-2)^i = 2 * (-2)^i = -1 * (-2)^(i + 1)\n```\n\nIn other words, we simply put a `0` at the position `i`, and we carry a `-1` to the next position `i + 1`. The question now is, what happens if `a_(i+1)` and `b_(i+1)` are both zero? We would want to set a `-1` at the position `i + 1`, but that\'s not possible. so we have to rewrite that:\n\n```\n-1 * (-2)^(i + 1) = (-2 + 1) * (-2)^(i + 1) = 1 * (-2)^(i + 1) + 1 * (-2)^(i + 2)\n```\n\nTherefore, if we have a sum of `-1` at a given position, we can simply put a `1` and carry a `+1` to the next position. Finally, this means we can have a sum of `2 + 1 = 3` at a given position; but that\'s easy to solve, as this is similar to the first situation: simply put a `1` rather than a `0` at the current position, and carry a `-1` to the next one.\n\nHere\'s the code implementing that:\n\n```\nclass Solution:\n \n def addNegabinary(self, arr1: List[int], arr2: List[int]) -> List[int]:\n carry = 0\n idx1 = len(arr1) - 1\n idx2 = len(arr2) - 1\n ans = []\n while not (idx1 == -1 and idx2 == -1 and carry == 0):\n val1 = arr1[idx1] if idx1 >= 0 else 0\n val2 = arr2[idx2] if idx2 >= 0 else 0\n val = val1 + val2 + carry\n if val >= 2: # case 2 or 3: put 0 or 1, and carry -1 to next position.\n ans.append(val % 2)\n carry = -1\n elif val == -1: # case -1: put a 1, and carry +1 to next position.\n ans.append(1)\n carry = 1\n else: # case 0 or 1: no carry in that case.\n ans.append(val)\n carry = 0\n idx1 = max(-1, idx1 - 1)\n idx2 = max(-1, idx2 - 1)\n while len(ans) >= 2 and ans[-1] == 0: # remove trailing zeros.\n ans.pop()\n return ans[::-1]\n``` | 11 | 0 | [] | 0 |
adding-two-negabinary-numbers | java 2ms solution with explanation | java-2ms-solution-with-explanation-by-pa-6e1w | The basic idea is sum bit by bit. The key is how to process carry. There are five situations for the bit sum:\n1. sum = 0 -> carry = 0, result = 0\n2. sum = 1 - | pangeneral | NORMAL | 2019-06-08T08:34:56.384792+00:00 | 2019-06-16T01:42:59.374923+00:00 | 2,269 | false | The basic idea is sum bit by bit. The key is how to process carry. There are five situations for the bit sum:\n1. sum = 0 -> carry = 0, result = 0\n2. sum = 1 -> carry = 0, result = 1\n3. sum = 2 -> carry = -1, result = 0\n4. sum = 3 -> carry = -1, result = 1\n5. sum = -1 -> carry = 1, result = 1\n\nHere, ```carry``` will be added to the sum of next calculation and ```result``` is what we put on current bit. We can either enumerate all five situations or use bit manipulation:\n1. carry = -1 * (sum >> 1)\n2. result = sum & 1\n\nto calculate ```carry``` and ```result``` quickly.\n\n```\npublic int[] addNegabinary(int[] arr1, int[] arr2) {\n int i1 = arr1.length - 1, i2 = arr2.length - 1, carry = 0;\n List<Integer> resultList = new ArrayList<Integer>();\n\t\n\t// 1. calculate sum of arr1 and arr2\n while (i1 >= 0 || i2 >= 0 || carry != 0) {\n int n1 = i1 >= 0 ? arr1[i1--] : 0;\n int n2 = i2 >= 0 ? arr2[i2--] : 0;\n int sum = n1 + n2 + carry;\n\t\tint result = sum & 1;\n carry = -1 * (sum >> 1) ;\n\t\tresultList.add(0, result); \n }\n\t\n\t// 2. remove leading zero\n int beginIndex = 0;\n while (beginIndex < resultList.size() && resultList.get(beginIndex) == 0)\n beginIndex++;\n\t\t\n if (beginIndex == resultList.size())\n return new int[]{0};\n int resultArray[] = new int[resultList.size() - beginIndex];\n for (int i = 0; i < resultArray.length; i++)\n resultArray[i] = resultList.get(i + beginIndex);\n return resultArray;\n}\n``` | 11 | 1 | ['Bit Manipulation', 'Java'] | 5 |
adding-two-negabinary-numbers | python, from engineer thinking | python-from-engineer-thinking-by-journey-lcg3 | simple and not optimized.\nwrite a func to convert from negabinary to dec and vice versa.\n\n\nclass Solution(object):\n def negabinary_to_dec(self,arr):\n | journeyboy | NORMAL | 2019-06-02T08:27:33.074527+00:00 | 2019-06-02T08:27:33.074582+00:00 | 1,581 | false | simple and not optimized.\nwrite a func to convert from negabinary to dec and vice versa.\n\n```\nclass Solution(object):\n def negabinary_to_dec(self,arr):\n s = 0\n d = 1\n i = len(arr)-1\n while i>=0:\n s += arr[i]*d\n i -= 1\n d *= -2\n return s\n \n def dec_to_negabinary(self,n):\n if n==0: return [0]\n ret = []\n while n != 0:\n a = abs(n%(-2))\n ret.append(a)\n n = (n-a)//(-2)\n return ret[::-1]\n \n def addNegabinary(self, arr1, arr2):\n """\n :type arr1: List[int]\n :type arr2: List[int]\n :rtype: List[int]\n """\n \n a = self.negabinary_to_dec(arr1)\n b = self.negabinary_to_dec(arr2)\n return self.dec_to_negabinary(a+b)\n``` | 11 | 0 | ['Python'] | 1 |
adding-two-negabinary-numbers | Java Solution With Explanation | java-solution-with-explanation-by-naveen-tdnr | Idea\n\n\n\n\nRef: https://en.wikipedia.org/wiki/Negative_base#Addition\n\nFirst observe the pattern, \n Carry = -sum/2 mathematically except for sum == -1.\nW | naveen_kothamasu | NORMAL | 2019-09-22T19:08:23.849747+00:00 | 2019-09-22T19:48:17.699975+00:00 | 999 | false | **Idea**\n\n\n\n\n*Ref*: https://en.wikipedia.org/wiki/Negative_base#Addition\n\nFirst observe the pattern, \n* Carry = -sum/2 mathematically except for sum == -1.\nWe can directly do this with special case when `sum == -1`. \nSince this is divison by 2<sup>k</sup> where k=1, we can right shift k times too. One observation here is we do not need special case for `sum == -1`. Why? Java right shift operator `>>` is actually the Signed right shift operator. So for sum = -1, we are doing \n`11 >> 1` which is agian `11` which is what we want.\n\n* Bit is the last bit that can be obtained with modulo 2.\nWe can do `(int)Math.abs(c) % 2` to get the last bit. We need to take absolute value here in Java because Java remainders can be negative and division is truncated to zero. Remember, modulo is never negative (those are the digits we use to represent the output so `-` sign shouldn\'t be present).\n\nWe can also use the observation that remainder is just the last k-bits when doing divison by 2<sup>k</sup>. So we just need to `&` with k 1\'s i.e. `c & 1`\n*Ref* https://stackoverflow.com/questions/15457893/java-right-shift-on-negative-number\nhttps://stackoverflow.com/questions/5385024/mod-in-java-produces-negative-numbers\n\n```\npublic int[] addNegabinary(int[] a1, int[] a2) {\n Stack<Integer> s = new Stack<>();\n int i=a1.length-1, j = a2.length-1, c = 0;\n while(i >= 0 || j >= 0 || c != 0){\n if(i >= 0)\n c += a1[i--];\n if(j >= 0)\n c += a2[j--];\n //s.push((int)Math.abs(c) % 2);\n s.push(c & 1);\n //c = c < 0 ? 1 : c <= 1 ? 0 : -1;\n c = -(c >> 1);\n }\n while(!s.isEmpty() && s.peek() == 0)\n s.pop();\n int[] res = new int[s.size()];\n i=0;\n while(!s.isEmpty())\n res[i++] = s.pop();\n return res.length == 0 ? new int[1] : res;\n }\n}\n``` | 5 | 1 | [] | 1 |
adding-two-negabinary-numbers | Java Base -2 | java-base-2-by-rbbah-ndh2 | Intuition\nSimilier to the base 2 convertion but less human friendly, when add to carry, instead of add 1, I adding -1. But this will lead to an issue, if both | RBBAH | NORMAL | 2023-06-04T18:08:21.008401+00:00 | 2023-06-04T18:08:21.008441+00:00 | 465 | false | # Intuition\nSimilier to the base 2 convertion but less human friendly, when add to carry, instead of add 1, I adding -1. But this will lead to an issue, if both arr1[i] and arr2[j] is 0 the result of arr1[i] + arr2[j] + carry could be -1, in such case we should borrow from higher bits, and set both carry and current val to 1\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nInstead of grinding this kind of leetcode problem to get into some "elite" company, I should probably start my own company and torture someone else with this kind mind twisting problem, and when they give me an optimized answer, I keep torturing them with questions like "why you want to work here"(Yeah! I know the true answer is just salary, but I want to hear some fancy lies). \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)$$ -->\n\n# Code\n```\nclass Solution {\n public int[] addNegabinary(int[] arr1, int[] arr2) {\n List<Integer> list = new ArrayList<>();\n int n = arr1.length;\n int m = arr2.length;\n int carry = 0;\n int i = n - 1, j = m - 1;\n while(i >= 0 && j >= 0) {\n int val = arr1[i] + arr2[j] + carry; // calculate current value\n int digit = 0;\n if (val < 0) {\n// special case : when arr1[i] == 0 and arr2[j] == 0 and carry = -1, \n// borrow value from i - 2, set carry and digit both to 1\n// e.g considering [1] + [1] which will leads to result [-1, 0], which \n// means -( (-2)^1 ), to represent this value, we need borrow (-2)^2 from \n//higher bit, and set current bit to 1 which means(-2)^1, that\'s why set digit and carry to 1\n// [1]\n// [1]\n// [-1,0] \n// [1,1,0]. borrow from arr[i - 1] to represent arr[i] = -1\n carry = 1;\n digit = 1;\n } \n else {\n carry = -(val / 2);\n digit = val % 2;\n }\n list.add(0, digit);\n --i;\n --j;\n }\n while(i >= 0) {\n int val = arr1[i] + carry;\n int digit = 0;\n if (val < 0) {\n carry = 1;\n digit = 1;\n } \n else {\n carry = -(val / 2);\n digit = val % 2;\n }\n list.add(0, digit);\n --i;\n }\n while(j >= 0) {\n int val = arr2[j] + carry;\n int digit = 0;\n if (val < 0) {\n carry = 1;\n digit = 1;\n } \n else {\n carry = -(val / 2);\n digit = val % 2;\n }\n list.add(0, digit);\n --j;\n }\n if (carry != 0) {\n if (carry == -1) {\n list.add(0, 1);\n list.add(0, 1);\n }\n else {\n //carry == 1\n list.add(0, carry);\n }\n }\n // remove leading zeros\n while(list.size() > 1 && list.get(0) == 0) {\n list.remove(0);\n }\n int[] ans = new int[list.size()];\n for (int k = 0; k < list.size(); ++k) {\n ans[k] = list.get(k);\n }\n return ans;\n }\n}\n``` | 4 | 0 | ['Java'] | 1 |
adding-two-negabinary-numbers | C++ in-place modification, time O(n), space O(1) | c-in-place-modification-time-on-space-o1-r48t | Binary add has only 5 cases:\n\n//value:0, binary: 0 0 0 -> 0 0 0\n//value:1, binary: 0 0 1 -> 0 0 1\n//value:-1, binary: 0 0 -1 -> 0 1 1\n//vaue: 2, binary 0 | tonyshaw | NORMAL | 2019-07-22T06:57:24.796414+00:00 | 2019-07-22T06:58:10.856537+00:00 | 802 | false | Binary add has only 5 cases:\n```\n//value:0, binary: 0 0 0 -> 0 0 0\n//value:1, binary: 0 0 1 -> 0 0 1\n//value:-1, binary: 0 0 -1 -> 0 1 1\n//vaue: 2, binary 0 0 2 -> 0 -1 0 -> 1 1 0\n//value: 3, binary 0 0 3 -> 0 -1 1 -> 1 1 1\n```\n```\nclass Solution {\npublic:\n vector<int> addNegabinary(vector<int>& arr1, vector<int>& arr2) {\n if (arr1.size() > arr2.size()) swap(arr1,arr2);\n arr2.insert(arr2.begin(), 3, 0);\n for (int i = arr1.size()-1, j = arr2.size()-1; j>=0; i--, j--) {\n if (i>=0) arr2[j]+=arr1[i];\n if (arr2[j] == -1) {\n arr2[j] = 1;\n arr2[j-1]++;\n } else if (arr2[j] == 2) {\n arr2[j] = 0;\n arr2[j-1]--;\n } else if (arr2[j] == 3) {\n arr2[j] = 1;\n arr2[j-1]--;\n }\n }\n while (arr2.front() == 0 && arr2.size()>1) arr2.erase(arr2.begin());\n return arr2;\n }\n};\n``` | 4 | 0 | [] | 0 |
adding-two-negabinary-numbers | C++ | Easy solution with detailed explanation | c-easy-solution-with-detailed-explanatio-ncp4 | Approach :\nEverything will be same as binary addition with base -2. Except when remainder is negative. \n\nsum = a1+a2+carry Possible values of sum are{ -1, 0, | deepak728 | NORMAL | 2022-05-28T19:35:24.626459+00:00 | 2022-05-28T19:35:24.626486+00:00 | 1,037 | false | # Approach :\nEverything will be same as binary addition with base -2. Except when remainder is negative. \n\n`sum = a1+a2+carry` Possible values of sum are` { -1, 0, 1, 2, 3} `\n`remainder = sum%(-2)` Possible values of remainder are` { -1, 0 , 1} `\n`carry = sum / (-2) `Possible values of carry are` { -1, 0, 1} `\nIn case of binary addition possible values of sum are` { 0, 1,2,3}` , remainders and carry are `{0 ,1} ` \n\nWe cannot have negative remainder so we should make it positive. \n\nAfter doing some iterations you will find that remainder is negative only when sum is negative. \n`N = divisor * quotient + remainder. `\nHere we are finding carry by dividing sum by (-2) so quotient is basically carry. \n```\nsum = (-2) * carry + r \nwhen sum is -1. \n-1 = (-2) * 0 -1 \nTo make remainder positive add and subtract -2. \n-1 = -2* 0 -2 -1 +2;\n-1 = -2 * ( calculated_carry + 1 ) +1 \n```\nTo make remainder positive we have to increment carry by 1 and add 2 to remainder. \n\n```\nvector<int> addNegabinary(vector<int>& arr1, vector<int>& arr2) {\n vector<int> ans;\n int l= max(arr1.size(),arr2.size())+2; // carry can be forwarded to maximum 2 positions. \n int a1,a2,sum, carry=0,r;\n reverse(arr1.begin(),arr1.end());\n reverse(arr2.begin(),arr2.end());\n int i=0; \n \n while(i<l){\n a1 = i<arr1.size() ? arr1[i] : 0;\n a2 = i<arr2.size() ? arr2[i] : 0; \n sum = a1+a2+carry;\n r= sum%(-2);\n carry= sum/ (-2);\n if(r<0){\n r+=abs(-2);\n carry =carry+1;\n }\n ans.push_back(r);\n i++;\n }\n while(ans.back()==0&&ans.size()!=1)\n ans.pop_back(); // remove trailing zeroes \n reverse(ans.begin(),ans.end());\n \n return ans;\n }\n```\n | 3 | 0 | ['C', 'C++'] | 0 |
adding-two-negabinary-numbers | C++ easy to understand and concise solution | c-easy-to-understand-and-concise-solutio-8702 | \tclass Solution {\n\tpublic:\n\t\tvector addNegabinary(vector& arr1, vector& arr2) {\n\t\t\treverse(arr1.begin(),arr1.end());\n\t\t\treverse(arr2.begin(),arr2. | jasperjoe | NORMAL | 2020-03-03T23:35:04.399156+00:00 | 2020-03-03T23:35:04.399204+00:00 | 980 | false | \tclass Solution {\n\tpublic:\n\t\tvector<int> addNegabinary(vector<int>& arr1, vector<int>& arr2) {\n\t\t\treverse(arr1.begin(),arr1.end());\n\t\t\treverse(arr2.begin(),arr2.end());\n\t\t\tint len(max(arr1.size(),arr2.size()));\n\t\t\tint carry=0;\n\t\t\tvector<int> ans;\n\t\t\tfor(int i=0;i<len+2;i++){\n\t\t\t\tint cur1=i<arr1.size() ? arr1[i]:0;\n\t\t\t\tint cur2=i<arr2.size() ? arr2[i]:0;\n\t\t\t\tint sum=cur1+cur2+carry;\n\t\t\t\tint r=sum%(-2);\n\t\t\t\tcarry=sum/(-2);\n\t\t\t\tif(r<0){\n\t\t\t\t\tcarry++;\n\t\t\t\t\tr+=abs(-2);\n\t\t\t\t} \n\t\t\t\tans.push_back(r);\n\n\t\t\t}\n\t\t\twhile(ans.size()>1 && ans.back()==0){\n\t\t\t\tans.pop_back();\n\t\t\t}\n\t\t\treverse(ans.begin(),ans.end());\n\t\t\treturn ans;\n\t\t}\n\t}; | 3 | 0 | ['C', 'C++'] | 0 |
adding-two-negabinary-numbers | [C++][Bit addition + carry] Easy to understand solution, beats 100% | cbit-addition-carry-easy-to-understand-s-6bde | Important Point to note\nCarry from ith term will always have to be subtracted from next whether it is odd power or even power. \neg : if for 2nd term(-2^2) we | dev1988 | NORMAL | 2019-06-02T08:00:14.435631+00:00 | 2019-06-08T03:27:06.792825+00:00 | 529 | false | **Important Point to note**\nCarry from ith term will always have to be subtracted from next whether it is odd power or even power. \neg : if for 2nd term(-2^2) we have both entries as 1(Carry 0), we have 4 + 4 = 8( i.e. 1 + 1 = 0, carry = 1)\nSo, for 3rd term(-2^3) i.e -8, if we have either entry as 1, we need to ignore one, giving the effect of **+8**(from carry) -**8**.\n \nThe only exception to this rule is when both terms are 0. This implies that we will have to forward the carry to next. But since that will cause double the val to be added/subtracted, we will update current to be 1 as well\n\n Example: C: 1 0 -1 1 \n 1 0 |0| 1\n 1 0 |0| 1\n + 0 1 1 0\n since carry == 1, prepend 11 to result.\n\t\t Final value = 1 1 0 1 1 0\n\nHope it helps :)\nAny comments, please feel free to share.\n```\nclass Solution {\npublic:\n vector<int> addNegabinary(vector<int>& arr1, vector<int>& arr2) {\n vector<int> res;\n if(arr1.size() < arr2.size()) swap(arr1, arr2);\n int i1, i2, dig, carry = 0;\n for(int i = 0; i < arr1.size(); i++){\n i1 = arr1[arr1.size() - 1 - i];\n i2 = (i < arr2.size() ? arr2[arr2.size()-1-i] : 0);\n \n dig = i1+i2-carry;\n if(dig < 0){\n res.push_back(1);\n //This ensures that for the next ith terms, we add the carry instead of subtracting, because this carry is not from this but previous term.\n carry = -1;\n }else{\n carry = dig/2;\n res.push_back(dig%2);\n }\n }\n if(carry){\n res.push_back(1);\n res.push_back(1);\n }\n \n for(int i = res.size() -1; i >= 0; i--){\n if(res[i] != 0) break;\n res.pop_back();\n }\n if(res.size() == 0) return {0};\n reverse(res.begin(), res.end());\n return res;\n }\n};\n``` | 3 | 0 | ['C'] | 0 |
adding-two-negabinary-numbers | Short Java Solution O(n) beats 100% no stack | short-java-solution-on-beats-100-no-stac-tcke | \nclass Solution {\n public int[] addNegabinary(int[] arr1, int[] arr2) {\n if(arr1.length < arr2.length) return addNegabinary(arr2, arr1); \n | kongfutea | NORMAL | 2019-06-02T05:02:05.395118+00:00 | 2019-06-02T05:02:05.395148+00:00 | 428 | false | ```\nclass Solution {\n public int[] addNegabinary(int[] arr1, int[] arr2) {\n if(arr1.length < arr2.length) return addNegabinary(arr2, arr1); \n int sho = arr2.length;\n int lo = arr1.length;\n int carry = 0; \n List<Integer> arr = new ArrayList<>(); \n for(int i = 1; i<=lo; i++){\n int num = 0; \n num = arr1[arr1.length-i] + ((i <= sho)? arr2[arr2.length-i] : 0) + carry; \n if(num == 2){\n arr.add(0,0);\n carry = -1; \n }else if(num == -1){\n arr.add(0, 1); \n carry = 1; \n }else if(num ==3){\n arr.add(0,1);\n carry = -1; \n }else{\n arr.add(0, num%2);\n carry = num/2;\n }\n }\n if(carry !=0){\n arr.add(0,1);\n arr.add(0,1);\n }\n while(arr.get(0) == 0 && arr.size() >1) arr.remove(0); \n int[] rst = new int[arr.size()];\n for(int i = 0; i< arr.size(); i++){\n rst[i] = arr.get(i);\n }\n return rst; \n } \n}\n``` | 3 | 2 | [] | 0 |
adding-two-negabinary-numbers | Adding Two Negabinary Numbers | adding-two-negabinary-numbers-by-ansh170-1zeb | Complexity
Time complexity: O(N)
Space complexity: O(1)
Code | Ansh1707 | NORMAL | 2025-04-05T07:49:17.638623+00:00 | 2025-04-05T07:49:17.638623+00:00 | 12 | false |
# Complexity
- Time complexity: O(N)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```python []
class Solution(object):
def addNegabinary(self, arr1, arr2):
"""
:type arr1: List[int]
:type arr2: List[int]
:rtype: List[int]
"""
res = []
carry = 0
while carry or arr1 or arr2:
if arr1:
carry += arr1.pop()
if arr2:
carry += arr2.pop()
res.append(carry & 1)
carry = -(carry >> 1)
while len(res) > 1 and res[-1] == 0:
res.pop()
return res[::-1]
``` | 2 | 0 | ['Array', 'Math', 'Python'] | 0 |
adding-two-negabinary-numbers | Solution in C++ | solution-in-c-by-ashish_madhup-l23v | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | ashish_madhup | NORMAL | 2023-03-31T15:24:26.882432+00:00 | 2023-03-31T15:24:26.882473+00:00 | 740 | 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)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n\tvector<int> addNegabinary(vector<int>& arr1, vector<int>& arr2) \n {\n\t\treverse(arr1.begin(),arr1.end());\n\t\treverse(arr2.begin(),arr2.end());\n\t\tint len(max(arr1.size(),arr2.size()));\n\t\tint carry=0;\n\t\tvector<int> ans;\n\t\tfor(int i=0;i<len+2;i++)\n {\n\t\t\tint cur1=i<arr1.size() ? arr1[i]:0;\n\t\t\tint cur2=i<arr2.size() ? arr2[i]:0;\n\t\t\tint sum=cur1+cur2+carry;\n\t\t\tint r=sum%(-2);\n\t\t\tcarry=sum/(-2);\n\t\t\tif(r<0)\n {\n\t\t\t\tcarry++;\n\t\t\t\tr+=abs(-2);\n\t\t\t} \n\t\t\tans.push_back(r);\n\t\t}\n\t\twhile(ans.size()>1 && ans.back()==0)\n {\n\t\t\tans.pop_back();\n\t\t}\n\t\treverse(ans.begin(),ans.end());\n\t\treturn ans;\n\t}\n};\n``` | 2 | 0 | ['C++'] | 0 |
adding-two-negabinary-numbers | Python 3 | Math, Two Pointers | Explanation | python-3-math-two-pointers-explanation-b-25z9 | Explanation\n- Math fact for -2 based numbers\n\t- 1 + 1 = 0, carry -1\n\t- -1 + 0 = 1, carry 1 \n\t- 1 + 0 = 1, carry 0\n\t- 0 + 0 = 0, carry 0\n\t- 0 + 1 = 1, | idontknoooo | NORMAL | 2021-08-05T03:06:28.492077+00:00 | 2021-08-05T03:06:28.492123+00:00 | 988 | false | ### Explanation\n- Math fact for -2 based numbers\n\t- `1 + 1 = 0, carry -1`\n\t- `-1 + 0 = 1, carry 1` \n\t- `1 + 0 = 1, carry 0`\n\t- `0 + 0 = 0, carry 0`\n\t- `0 + 1 = 1, carry 0`\n\t- `-1 + 1 = 0, carry 0`\n\t- `-1 + -1 is not possible`\n- Based on above fact, we can do a two pointer addition from right to left\n- Remember to count the `carry` and remove the leading `0` before return the answer\n### Implementation\n```\nclass Solution:\n def addNegabinary(self, arr1: List[int], arr2: List[int]) -> List[int]:\n ans = list()\n m, n = len(arr1), len(arr2)\n i, j = m-1, n-1\n def add(a, b): # A helper function to add -2 based numbers\n if a == 1 and b == 1:\n cur, carry = 0, -1\n elif (a == -1 and b == 0) or (a == 0 and b == -1): \n cur = carry = 1\n else: \n cur, carry = a+b, 0\n return cur, carry # Return current value and carry\n carry = 0\n while i >= 0 or j >= 0: # Two pointers from right side\n cur, carry_1, carry_2 = carry, 0, 0\n if i >= 0:\n cur, carry_1 = add(cur, arr1[i])\n if j >= 0: \n cur, carry_2 = add(cur, arr2[j])\n carry = carry_1 + carry_2\n ans.append(cur)\n i, j = i-1, j-1\n ans = [1,1] + ans[::-1] if carry == -1 else ans[::-1] # Add [1, 1] if there is a carry -1 leftover\n for i, v in enumerate(ans): # Remove leading zero and return\n if v == 1:\n return ans[i:]\n else:\n return [0]\n``` | 2 | 0 | ['Math', 'Two Pointers', 'Python', 'Python3'] | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.