Skip to content

Instantly share code, notes, and snippets.

View gtaing1's full-sized avatar

Gigi Taing gtaing1

View GitHub Profile
/**
Problem
Convert a sorted array into a balanced BST. Return the root of the created tree.
Function Signature:
func arrayToBST(input: [Int]) -> Node
Target runtime and space complexity:
Runtime: O(n)
Space: O(1), not including space used to create BST, otherwise O(n)
Examples:
/*
You are given a series of inputs representing delivery events. Each event is represented by an array of length 3:
[1, 1591846068, 0]
The first element is an order number
The second is the timestamp
The third is either 0 (representing a pickup) or 1 (representing a dropoff)
Given a series of events, return the total active time, calculated by the period of time where they have an active delivery (if they've dropped everything off, they are not considered active until they pick something up again).
@gtaing1
gtaing1 / Algos
Last active April 16, 2022 20:55
/*
Rating of Confidence: 80%
Practiced Date: 04/15/2022
Q. Given an array of positive integers, find the first element that occurs k number of times. If no element occurs k times, return -1, and you may assume k is greater than 0.
Examples:
• Given an array: [1, 2, 2, 3, 3], k: 2 // returns 2
• Given an array: [], k: 1 // returns -1
*/
@gtaing1
gtaing1 / newsletter-popup.js
Created December 2, 2021 02:11 — forked from vanpariyar/newsletter-popup.js
Newsletter popup with session storage
if (typeof(Storage) !== "undefined") {
// Store
function showPopup(){
window.setTimeout(function () {
$('#newsletter-modal').modal('show');
sessionStorage.setItem("popup", 'hide');
},6000);
}
if( !sessionStorage.getItem("popup")){
sessionStorage.setItem("popup", 'show');
if (typeof (CFADashboard) == 'undefined') {
var CFADashboard = {};
}
CFADashboard.AdminOnlineVideoControl = (function () {
var _config;
return {
init: function (config) {
_config = config;
select
UserName as Name,
Email as email,
Role as role,
PageVisited as ViewedPage,
/*Count(PageVisited) as NumberofHits,*/
COUNT(CAST(Date as date)) as NumberOfVisits,
CAST(Date as date) as LastVisitedDate
from [dbo].[UserActivityLog]
where EMAIL NOT LIKE '%starcom%'
@gtaing1
gtaing1 / response-header.js
Created May 1, 2018 13:36 — forked from thsutton/response-header.js
Get the value of an HTTP response header in JavaScript
/**
* Read the value of a header in the current document.
*
* This uses a [single] XMLHTTPRequest to do a HEAD of the current document
* and fetch HTTP response header values. Note that the implementation is
* rather stupid in that it spins waiting for the XMLHTTPRequest to complete
* if it hasn't been called yet.
*
* @param name string
(function(){
var data1;
var data2;
d3.text("display.txt").then(function(text) {
var cells=text.split("\n").map(function(el){
return el.split("|");
(function(){
var data1;
var data2;
d3.text("display.txt").then(function(text) {
var cells=text.split("\n").map(function(el){
return el.split("|");
@gtaing1
gtaing1 / test.js
Created July 23, 2017 03:32 — forked from markkernke/test.js
Tableau JS API usage for Syncing Metric Names between datasources
/**********************************************************
*
* Currently does not work due to http://community.tableau.com/thread/131070
*
*********************************************************/
var viz = tableau.VizManager.getVizs()[0]