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
| set nocompatible | |
| source $VIMRUNTIME/vimrc_example.vim | |
| source $VIMRUNTIME/mswin.vim | |
| behave mswin | |
| set diffexpr=MyDiff() | |
| function MyDiff() | |
| let opt = '-a --binary ' | |
| if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif | |
| if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif |
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
| from scipy.stats import t | |
| import numpy | |
| def sampleStdev(samples): | |
| mean = numpy.mean(samples) | |
| squareSamples = [ numpy.power(x - mean, 2) for x in samples] | |
| sumSqr = numpy.sum(squareSamples) | |
| sampleStdev = numpy.sqrt(sumSqr / (len(samples) - 1)) | |
| return sampleStdev |
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
| /*You are given large numbers of logs, each one of which contains a start time (long), end time (long) and memory usage (int). The time is recorded as MMDDHH (100317 means October 3rd 5PM) Write an algorithm that returns a specific time (hour) when the memory usage is the highest. If there are multiple answers, return the first hour. | |
| */ | |
| #include <cstdio> | |
| #include <sstream> | |
| #include <fstream> | |
| #include <map> | |
| #include <vector> | |
| using namespace std; |
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
| /*Given a string and array of strings, find whether the array contains a string with one character difference from the given string. Array may contain string of different lengths. | |
| Ex: Given string | |
| banana | |
| and array is [bana, apple, banaba, bonanza, banamf] | |
| and the output should be true as banana and banaba are one character difference. | |
| banana1, banan | |
| http://www.careercup.com/question?id=5760697411567616 | |
| */ | |
| #include <my_epi/common.h> | |
| struct TrieNode { |
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
| /* Given an array of integers A and an integer k, find a subarray that contains the largest sum, subject to a constraint that the sum is less than k? | |
| */ | |
| pair<int, int> FindSubarrayClosestToK(const vector<int>& a, int k) { | |
| pair<int, int> range{0, -1}; | |
| if (a.empty()) return range; | |
| map<int, int> sum_to_idx; | |
| int sum = 0; | |
| int min_diff = k; |
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
| /* Given an array of integers A and an integer k, find a subarray whose sum is k */ | |
| typedef pair<int, int> Range; | |
| Range FindSubarrayWithSum(const vector<int>& a, int k) { | |
| Range result{ -1, -1}; | |
| if (a.empty()) | |
| return result; | |
| unordered_map<int, int> sum_to_idx; | |
| int sum = 0; | |
| sum_to_idx.emplace(sum, -1); // cumulative sum at -1 is 0 | |
| for (int i = 0; i < a.size(); ++i) { |
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
| /* Find longest increasing/nondecreasing subsequence in an array */ | |
| int LongestIncreasingSubsequence(const vector<int>& a) { | |
| if (a.empty()) return 0; | |
| vector<int> ends; // endpoint of active array | |
| ends.emplace_back(a[0]); | |
| for (int i = 1; i < a.size(); ++i) { //? ++i or i++ | |
| auto it = lower_bound(ends.begin(), ends.end(), a[i]); | |
| if (it != ends.end()) { | |
| *it = a[i]; | |
| } else { |
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
| pair<int, int> FindSubarrayClosestToK(const vector<int>& a, int k) { | |
| pair<int, int> range{0, -1}; | |
| if (a.empty()) return range; | |
| map<int, int> sum_to_idx; | |
| int sum = 0; | |
| int min_diff = k; | |
| sum_to_idx.emplace(0, -1); // S[-1] = 0 so push 0, -1 here! | |
| for (int i = 0; i < a.size(); ++i) { |
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
| struct Meeting { | |
| int start, end; | |
| }; | |
| struct CompareMeeting { | |
| bool operator()(const Meeting& a, const Meeting& b) const { | |
| if (a.start == b.start) return a.end < b.end; | |
| return a.start < b.start; | |
| } | |
| }; | |
| bool IsValidSchedule(vector<Meeting> meetings) { |
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
| int FindMinTimePeriod(const vector<int>& tasks, int K) { | |
| unordered_map<int, int> task_to_last_time; | |
| int cur_time = 0; | |
| for (int i = 0; i < tasks.size(); ++i) { | |
| int cur_task = tasks[i]; | |
| auto it = task_to_last_time.find(cur_task); | |
| if (it != task_to_last_time.end()) { | |
| cur_time = max(cur_time, it->second + K + 1); | |
| it->second = cur_time; | |
| } else { |