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 May 21, 2025 18:06
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
@mathcodes
mathcodes / nosqlvssql.md
Last active August 2, 2022 23:32
NoSql vs Sql

NoSQL vs SQL Databases

Description

The following information is straight from source: https://www.mongodb.com/nosql-explained/nosql-vs-sql

TLDR: NoSQL (“non SQL” or “not only SQL”) databases were developed in the late 2000s with a focus on scaling, fast queries, allowing for frequent application changes, and making programming simpler for developers. Relational databases accessed with SQL (Structured Query Language) were developed in the 1970s with a focus on reducing data duplication as storage was much more costly than developer time. SQL databases tend to have

  • rigid
  • complex, tabular schemas

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);