Skip to content

Instantly share code, notes, and snippets.

View mathcodes's full-sized avatar
💭
🧮 💻 🎵 🧮 💻 🎵 🧮 💻 🎵

Jon Christie mathcodes

💭
🧮 💻 🎵 🧮 💻 🎵 🧮 💻 🎵
View GitHub Profile
@mathcodes
mathcodes / dsa_pattern.md
Last active October 3, 2024 10:12
14 DSA Patterns to Master

14 Coding Patterns To Master

This is a collection of coding patterns I have learned to solve not only some of the most common problems, but the 14 patterns (yes, there are way more than 14, but the point here is taking 6 months of preparation and condensing it into a 30 minute read that would not take more than 1-2 weeks to master. I have found these problems and patterns to be the most useful in that the data structures and algorithms are used in many other problems and become familiar over time. Good luck!

Please feel free to comment if you got some value or find any errors!

Thanks!

Table of Contents

API developer :
Leveraged Partitioning:
Leveraged partitioning is a technique used to distribute and store data across multiple servers or database shards. This approach is commonly employed in distributed systems to manage large datasets efficiently. As an API developer, your role would involve designing APIs that interact with the underlying data storage, which is partitioned.
API tasks related to leveraged partitioning:
a. Data distribution: You need to ensure that data is correctly distributed among the partitions to maintain a balanced load across servers.
b. Shard key management: Decide how to select shard keys or partition keys for efficient data retrieval.
c. Request routing: Implement logic to route API requests to the appropriate shard based on the partition key.
d. Fault tolerance: Plan for redundancy and replication across partitions to handle server failures gracefully.
Caching Solutions (like Memcached):

Reversing a string in 4 languages: JavaScript, Java, C++, and Python

JavaScript

function reverse(str) {
  // Convert the string into an array of characters
  var arr = str.split('');

 // Reverse the array

LeetCode 2462. Total Cost to Hire K Workers

C++ Approach 1:

class Solution {
public:
    long long totalCost(vector<int>& cost, int k, int c) {
        priority_queue<pair<int,int>>pq; // Priority queue to store costs in descending order along with their corresponding type
        map<int,int>m; // Map to keep track of the occurrences of each type
        for(int i=0;i<c;i++){
@mathcodes
mathcodes / Understanding Legacy Code and Dealing with it in a Job Environment.md
Created June 24, 2023 16:58
Understanding Legacy Code and Dealing with it in a Job Environment

Understanding Legacy Code and Dealing with it in a Job Environment

Outline:

I. Introduction

  • Definition of legacy code
  • Importance of understanding and dealing with legacy code in a job environment

II. Why Does Legacy Code Exist?

  • A. Historical reasons

The Component Lifecycle

Mounting (created/inserted into DOM)

These methods are called in the following order when an instance of a component is being created and inserted into the DOM (bold implies commonly used):

  • constructor()
  • static get­Derived­State­From­Props
  • render() *
  • ­React updates ­D­O­M and refs
  • component­Did­Mount()

array.forEach

Write a function that takes an array of numbers and a function as parameters. The function parameter should do something to a numbers (increment, double, decrement, etc) and return the result. Your function should return the array that results from applying the function parameter to each element in the number arrav.

SOLUTION

const map = (array, func) => {
    const newArray = [];
    array.forEach((num) => {
 const output = func(num);