Programming is an art that cannot be learned in a year or so. You need to practice it continuously and regularly to be pro at it. But, before becoming a pro, some basic fundamentals and foundations are important. This guide will tell you about some of the efficient practices to use while programming.

Sounds exciting? Let’s get right into it!

I won’t spend too much time here since if you’re reading this, you likely have a pretty solid idea of what programming and coding is.

It’s just a formalized version of the logic, in the vocabulary and syntax of the…

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, this is a double-edged sword as being dynamically-typed is what makes Python such an elegant language. *So Python is a slower language to run, but faster to type.*

Let’s look at some minor tips that could have a major impact on your overall code performance in the long run.

I’m…

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.

`class Solution:`

def sortColors(self, nums: List[int]) -> None:

nums.sort()

*Time Complexity: O(nlogn)*

*Space Complexity: No extra space*

The efficient approach is to take 3 pointers i.e. *low**, **high**,* and* *** mid**. Start the

- As soon as the
*mid*pointer reaches an element with a value…

*Problem Link:*

*Problem Statement:*

You are given a **0-indexed** integer array `nums`

and an integer `k`

.

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. That is, you can jump from index `i`

to any index in the range `[i + 1, min(n - 1, i + k)]`

**inclusive**.

You want to reach the last index of the array (index `n - 1`

). Your **score** is the **sum** of all `nums[j]`

for each index `j`

you visited in the array.

Return *the **maximum…*

*Problem Link:*

*Problem Statement:*

Given two integer arrays `preorder`

and `inorder`

where `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*.

*Example 1:*

**Input:** preorder = [3,9,20,15,7], inorder = [9,3,15,20,7]

**Output:** [3,9,20,null,null,15,7]

*Example 2:*

**Input:** preorder = [-1], inorder = [-1]

**Output:** [-1]

*Constraints:*

`- 1 <= preorder.length <= 3000`

- inorder.length == preorder.length

- -3000 <= preorder[i], inorder[i] <= 3000

- preorder and inorder consist of **unique** values

- Each value of inorder also appears in preorder

- preorder is **guaranteed** to be the preorder traversal of the…

*Problem Link:*

*Problem Statement:*

You are given an integer array `cost`

where `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 `1`

.

Return *the minimum cost to reach the top of the floor*.

*Example 1:*

**Input:** cost = [10,15,20]

**Output:** 15

**Explanation:** Cheapest is: start on cost[1], pay that cost, and go to the top.

*Example 2:*

**Input:** cost = [1,100,1,1,1,100,1,1,100,1]

**Output:** 6

**Explanation:** Cheapest is: start on cost[0], and only step on…

*Problem Link:*

*Problem Statement:*

Given an unsorted array of integers `nums`

, return *the length of the longest consecutive elements sequence.*

You must write an algorithm that runs in `O(n)`

time.

*Example 1:*

**Input:** nums = [100,4,200,1,3,2]

**Output:** 4

**Explanation:** The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4.

*Example 2:*

**Input:** nums = [0,3,7,2,5,8,4,6,0,1]

**Output:** 9

*Constraints:*

`- 0 <= nums.length <= 10^5`

- -10^9 <= nums[i] <= 10^9

*Brute Force:*

`def longestConsecutiveSequence(A: List[int], n: int) -> int:`

longestStreak = 0

for i in range (n)…

*Problem Link:*

*Problem Statement:*

You are given two integers `n`

and `k`

and two integer arrays `speed`

and `efficiency`

both of length `n`

. There are `n`

engineers numbered from `1`

to `n`

. `speed[i]`

and `efficiency[i]`

represent the speed and efficiency of the `ith`

engineer respectively.

Choose **at most** `k`

different engineers out of the `n`

engineers to form a team with maximum **performance**.

The performance of a team is the sum of their engineers’ speeds multiplied by the minimum efficiency among their engineers.

Return *the maximum performance of this team*. …

*Problem Link:*

*Problem Statement:*

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 `'9'`

to `'0'`

, or `'0'`

to be `'9'`

. Each move consists of turning one wheel in one slot.

The lock initially starts at `'0000'`

, a string representing the state of the 4 wheels.

You are given a list of `deadends`

dead ends, meaning if the lock displays any of these codes, the wheels of the lock…

*Problem Link:*

*Problem Statement:*

Given a rectangular cake with height `h`

and width `w`

, and two arrays of integers `horizontalCuts`

and `verticalCuts`

where `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 the rectangular cake to the `jth`

vertical cut.

*Return the maximum area of a piece of cake after you cut at each horizontal and vertical position provided in the arrays **horizontalCuts** and **verticalCuts**. *Since the answer can be a huge number, return this modulo 10^9 + 7.

*Example 1:*

**Input…**

I am a B.Tech. Undergrad and loves programming. Scholar at Google Women Techmakers and currently exploring different tech fields.