A CPU cache is a hardware cache which helps reduce the cost from main memory access. It is a smaller and faster memory part which locates closer to a CPU core than the main memory. Most modern CPUs have mulitple level of caches like L1, L2, and L3. When trying to read and write the main memory, the processor will first check if the data already exists in its local cache.

Read more »

Overview

Once upon a time, in a quiet suburban neighborhood, there lived a mischievous boy named Bill. Bill was unlike any other child in his school. He had a huge brain, a gift that often led him down a wayward path. While his classmates diligently attended school, Bill had a knack for finding ways to skip it.

Read more »

What are Virtual Kubernetes Clusters(VCluster)?

Virtual clusters are fully working Kubernetes clusters that run on top of other Kubernetes clusters. Compared to fully separate “real” clusters, virtual clusters reuse worker nodes and networking of the host cluster. They have their own control plane and schedule all workloads into a single namespace of the host cluster. Like virtual machines, virtual clusters partition a single physical cluster into multiple separate ones.

Read more »

index()

The index() method returns the index of the specified element in the list.

1
2
3
4
5
6
7
8
animals = ['cat', 'dog', 'rabbit', 'horse']

# get the index of 'dog'
index = animals.index('dog')

print(index)

# Output: 1

set()

1
2
3
4
5
6
triplets = set() # automatically remove duplicates
triplets.add((1,2,3))
triplets.add((1,2,4))
triplets.add((1,2,3))
print(triplets)
# output: {(1, 2, 3), (1, 2, 4)}

isalnum()

The isalnum() method returns True if all the characters are alphanumeric, meaning alphabet letter (a-z) and numbers (0-9).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Solution:
def isPalindrome(self, s: str) -> bool:
left, right = 0, len(s) - 1
while left < right:
if not s[left].isalnum():
left += 1
continue
if not s[right].isalnum():
right -= 1
continue

if s[left].lower() != s[right].lower():
return False

left += 1
right -= 1

return True

ord()

ord() function returns the Unicode code from a given character.

Read more »

What is Dynamic Programming?

Dynamic Programming is mainly an optimization over plain recursion. Wherever we see a recursive solution that has repeated calls for same inputs, we can optimize it using Dynamic Programming. The idea is to simply store the results of subproblems, so that we do not have to re-compute them when needed later. This simple optimization reduces time complexities from exponential to polynomial.

Read more »

Moore Voting Algorithm

[Leetcode 169] Majority Element

Given an array nums of size n, return the majority element.

The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array.

Read more »

[Leetcode 121] Best Time to Buy and Sell Stock

You are given an array prices where prices[i] is the price of a given stock on the ith day.

You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.

Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.

Read more »
0%