Problem Description
Given a DataFrame named players, determine the number of rows and columns it contains and return the result as an array in the form [number of rows, number of columns].
Key Insights
- The DataFrame’s shape is an inherent property that represents its dimensions.
- In Python (using pandas), the shape attribute returns a tuple (rows, columns).
- In other languages that do not have a built-in DataFrame, the same concept can be emulated by treating the structure as a collection of rows, where each row is a collection of columns.
Space and Time Complexity
Time Complexity: O(1) – accessing the dimensions is a constant time operation. Space Complexity: O(1) – only a fixed amount of additional space is used.
Solution
The solution leverages the fact that DataFrames inherently store their dimensions. For example, in Python, using the pandas library, the players DataFrame has an attribute called shape that returns a tuple: (number of rows, number of columns). The solution simply extracts and returns these values in the required format. For languages without native DataFrame support, the common approach is to represent the DataFrame as a list or vector of rows (with each row being a list/array of columns) and then use the length of the list for rows and the length of any row (if it exists) for columns.