This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Node { | |
| constructor(value, next = null) { | |
| this.value = value; | |
| this.next = next; | |
| } | |
| } | |
| const findCycleStart = function (head) { | |
| let slow = head; | |
| let fast = head; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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++ | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
NewerOlder