EasyNo. 2794LeetCode Premium
Create Object from Two Arrays — LeetCode 2794 Python Solution
- Topics
- JavaScript
- Reading time
- 2 min
- Source
- leetcode.com
The problem
Given two arrays keysArr and valuesArr, return a new object obj. Each key-value pair in obj should come from keysArr[i] and valuesArr[i].
Example
- Input
- keysArr = ["a", "b", "c"], valuesArr = [1, 2, 3]
- Output
- {"a": 1, "b": 2, "c": 3}
- Explanation
- The keys "a", "b", and "c" are paired with the values 1, 2, and 3 respectively.
Python solution
class Solution:
def createObject(self, keysArr: List[str], valuesArr: List[int]) -> dict:
obj = {}
for k, v in zip(keysArr, valuesArr):
obj[k] = v
return objComplexity
- Time
- O(n)
- Space · auxiliary
- O(n)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 2785 | Sort Vowels in a String | Medium |
| 0056 | Merge Intervals | Medium |
| 0147 | Insertion Sort List | Medium |
| 0164 | Maximum Gap | Medium |
| 0274 | H-Index | Medium |
| 0406 | Queue Reconstruction by Height | Medium |
Frequently asked questions
- How hard is LeetCode 2794. Create Object from Two Arrays?
LeetCode 2794. Create Object from Two Arrays is rated Easy on LeetCode.
- What is the time complexity of LeetCode 2794. Create Object from Two Arrays?
The Python solution on this page runs in O(n).
- What is the space complexity of LeetCode 2794. Create Object from Two Arrays?
The Python solution on this page uses O(n) auxiliary space.
- What topics does LeetCode 2794. Create Object from Two Arrays cover?
LeetCode 2794. Create Object from Two Arrays is tagged JavaScript on LeetCode.
- Is LeetCode 2794. Create Object from Two Arrays a premium problem?
Yes. LeetCode 2794. Create Object from Two Arrays is a LeetCode Premium problem, so the full statement and test cases require a paid LeetCode subscription.