Skip to content

Instantly share code, notes, and snippets.

View felixfirefighter's full-sized avatar
💫
Looking at the stars

Felix Lee felixfirefighter

💫
Looking at the stars
View GitHub Profile
<script>
import { onMount } from 'svelte';
import { createChart } from 'lightweight-charts';
let chartDiv;
let overlayCanvasEl;
let chart, series;
let mode = 'view'; // "view", "point", "timeRange", "priceRange", or "scribble"
// Data structures for annotations and drawings
@felixfirefighter
felixfirefighter / minMeetingRoom.js
Created September 16, 2022 09:47
Minimum Meeting Room
const Heap = require('./collections/heap'); //http://www.collectionsjs.com
function minMeetingRooms(meetings) {
meetings.sort((a, b) => a.start - b.start);
// min heap with smallest end time at the top
let minRooms = 0,
minHeap = new Heap([], null, ((a, b) => b.end - a.end));
for (i = 0; i < meetings.length; i++) {
// remove all the meetings that have ended (if the end time of previous meetings is less/equal to the start time of
@felixfirefighter
felixfirefighter / isPalindrome.js
Created June 26, 2022 11:46
234. Palindrome Linked List
/**
* Definition for singly-linked list.
* function ListNode(val, next) {
* this.val = (val===undefined ? 0 : val)
* this.next = (next===undefined ? null : next)
* }
*/
/**
* @param {ListNode} head
* @return {boolean}
@felixfirefighter
felixfirefighter / index.tsx
Last active June 19, 2022 11:03
sitemap/index.tsx
const Sitemap = () => {
return <></>;
};
export async function getServerSideProps({ res }) {
// Get sitemap.xml from S3 bucket
const response = await fetch(
"https://felix-medium-bucket-1.s3.ap-southeast-1.amazonaws.com/medium-1/sitemap.xml"
);
const text = await response.text();
@felixfirefighter
felixfirefighter / findCycleStart.js
Created June 13, 2022 17:33
Find Start of Cycle
class Node {
constructor(value, next = null) {
this.value = value;
this.next = next;
}
}
const findCycleStart = function (head) {
let slow = head;
let fast = head;
@felixfirefighter
felixfirefighter / minWindowSort.js
Created June 13, 2022 14:20
Minimum Window Sort
const minWindowSort = function(arr) {
let left = 0
let right = arr.length - 1
let minNum = Infinity, maxNum = -Infinity
// Find the first(left) element that is out of order
// We keep checking whether the current element is less than the next one
while(left <= right && arr[left] <= arr[left + 1]) {
left++
}
const findProductSum = function (arr, target) {
const result = [];
let left = 0;
let product = 1;
for (let right = 0; right < arr.length; right++) {
// Multiply current element to product
product = product * arr[right];
// We want to find product that is less than target.
/**
* @param {number[]} nums
* @param {number} target
* @return {number}
*/
var threeSumClosest = function (arr, target) {
// Sort the array from small to large number
arr.sort((a, b) => a - b);
let result = Infinity;
@felixfirefighter
felixfirefighter / word-concatenation.js
Last active June 11, 2022 16:51
Word Concatenation
const findWordConcatenation = function (str, words) {
const result = [];
const wordLength = words[0].length;
const wordCount = words.length
const wordMap = {};
for (let i = 0; i < wordLength; i++) {
const word = words[i];
// Word does not exist, initialize it to 0
if (!(word in wordMap)) {
@felixfirefighter
felixfirefighter / word-concatenation.js
Last active June 11, 2022 16:40
Word Concatenation
const findWordConcatenation = function (str, words) {
const result = [];
const wordLength = words[0].length;
const wordCount = words.length
const wordMap = {};
for (let i = 0; i < wordLength; i++) {
const word = words[i];
if (!(word in wordMap)) {
wordMap[word] = 0;