I’m sure you heard a lot of people complaining that Python is so slow. I see people compare Python to C in the context of performance only, but they don’t compare in the context of fast development.
It is a dynamically-typed language meaning its variable types are not predefined, although…
The first approach for this problem that comes to mind is to sort the array. Thus approach will work in O(nlogn) if we sorting techniques like merge sort. So that’s the naive solution to this problem.
def sortColors(self, nums: List[int]) -> None:
Time Complexity: O(nlogn)
You are given a 0-indexed integer array
nums and an integer
You are initially standing at index
0. In one move, you can jump at most
k steps forward without going outside the boundaries of the array. …
Given two integer arrays
preorder is the preorder traversal of a binary tree and
inorder is the inorder traversal of the same tree, construct and return the binary tree.
Input: preorder = [3,9,20,15,7], inorder = [9,3,15,20,7]
You are given an integer array
cost[i] is the cost of
ith step on a staircase. Once you pay the cost, you can either climb one or two steps.
You can either start from the step with index
0, or the step with index…
Given an unsorted array of integers
nums, return the length of the longest consecutive elements sequence.
You must write an algorithm that runs in
Input: nums = [100,4,200,1,3,2]
Explanation: The longest consecutive elements sequence is [1, 2, 3, 4]. …
You are given two integers
k and two integer arrays
efficiency both of length
n. There are
n engineers numbered from
efficiency[i] represent the speed and efficiency of the
ith engineer respectively.
Choose at most
You have a lock in front of you with 4 circular wheels. Each wheel has 10 slots:
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'. The wheels can rotate freely and wrap around: for example, we can turn
Given a rectangular cake with height
h and width
w, and two arrays of integers
horizontalCuts[i] is the distance from the top of the rectangular cake to the
ith horizontal cut and similarly,
verticalCuts[j] is the distance from the left of…