├── .gitignore ├── README.md ├── TESTING.md ├── algorithms ├── interview_questions │ └── airbnb_sorting │ │ ├── problem.md │ │ └── solutions │ │ └── hy-solution.js └── linked_lists │ ├── doubly_linked_list_exercise │ └── exercise.md │ ├── prep.md │ └── simple_linked_list_exercise │ ├── exercise.md │ ├── solutions │ ├── arf_solution.js │ ├── hy_solution.js │ └── your_solution.js │ └── tests │ ├── simple_linked_list_example.spec.js │ └── test.rb ├── karma.conf.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dbc-algorithms 2 | Welcome! This is the repo of the DBC Algorithms Study Group. This is a rather slap-dashed repo, so take from it or give to it what you will! 3 | 4 | 5 | ### Contribution/Submission Guidelines 6 | 7 | None of this forking stuff! Want to be a collaborator? Join the FB group and ping Hanah Yendler with your Github username! 8 | 9 | If you want to create an exercise, interview question, or solution, check out a new branch off of master, do yo thang, and then submit a pull request and get TWO approvals from other collaborators. 10 | 11 | Adding a new exercise? Totally okay to post from elsewhere, just make sure to credit the source in the readme! Exercise instructions should also be language free. 12 | 13 | Note: You can't push to master, except for me (Hanah, repo owner) Mwuahahahaha. So you gotta check out a branch to get your changes in. 14 | 15 | Have a partial algorithm solution, but are stuck and don't want to look at the answer just yet? Submit a pull request, tag a couple of co-conspirators, and ask for help! Edit, commit, and repush and explicity ask for review for a merge :) 16 | 17 | Please only merge working solution code. K thx bai. 18 | 19 | 20 | ### Directory organizational guidelines 21 | - let's use underscores instead of spaces 22 | - let's use lowercase instead of uppercase (good practice in general, as uppercase file/folder names can eff file paths up) 23 | - let's have solutions be set up as: 24 | - `simple_linked_list_exercise` 25 | - `hy_solution` 26 | - `hy_solution.js` 27 | - `hy_solution.spec.js` 28 | - `amf_solution` 29 | - `amf_solution.rb` 30 | - `amf_solution_test.rb` 31 | - write in whatever language you want (then maybe write a test in that language if it doesn't exist :P) 32 | 33 | ### Testing 34 | - testing can (IMHO is - Adam) be fun, useful, and really help to grasp how your solution is working 35 | - each week someone will post example spec files in different languages for you to use and model in your own solutions 36 | - you can add more examples to help in the process, and you'll want to edit them to match your naming 37 | - solutions should be namespaced so as not to conflict with other solution 38 | - see the TESTING.md with any question about how to implent, or reach out to the facebook group 39 | 40 | ### Housekeeping 41 | I can't manage this by myself, so I need your help to make this repo AWESOME. Also, TDD! Write tests for the exercises. 42 | 43 | Have a guideline that should be on here? Make a pull request and tag @hyendler! 44 | 45 | -------------------------------------------------------------------------------- /TESTING.md: -------------------------------------------------------------------------------- 1 | ##Testing Solutions 2 | 3 | In a general sense, the goal it to make it easy to create, and run unit tests for each solution (not in a mandatory draconian way) easy so that all of us can get used to creating solutions that are easy to test, and sure that we are on the right track. 4 | 5 | Good unit tests make getting started with a difficult problem easy, because the first few tests are the simplest inputs we can imagine, and are often trivial to handle. Then, as we get more momentum the tests let us know when our change effected a easier case. 6 | 7 | ###Javascript 8 | 9 | One of the most familiar languages around, and a very well documented testable language. This repo lets you run javascript tests through the npm test command. 10 | 11 | To get up and running, make sure you have node installed [download](https://nodejs.org/en/download/). Then run `npm install` from the top of this repo. This will download all the dependencies to run the javascript test. If you are interested in the set up of this, see [jasmine](https://jasmine.github.io/) and [karma](https://karma-runner.github.io/1.0/index.html). 12 | 13 | A simple add function test would look like this: 14 | 15 | describe('ABC_calculator.add', function () { 16 | it('should return correct sum', function () { 17 | expect(ABC_calculator.add(1,1)).toEqual(2); 18 | }); 19 | }); 20 | 21 | You'll probably notice this syntax is very similar to Rspec. 22 | 23 | IMPORTANT NOTE: In order to not mess with anyone elses solution, the add function is namespaced to an object with your initials plus the challenge name. 24 | -------------------------------------------------------------------------------- /algorithms/interview_questions/airbnb_sorting/problem.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyendler/dbc-algorithms/7833218d3562e8937d5480dd89244b822e844830/algorithms/interview_questions/airbnb_sorting/problem.md -------------------------------------------------------------------------------- /algorithms/interview_questions/airbnb_sorting/solutions/hy-solution.js: -------------------------------------------------------------------------------- 1 | // Name: Hanah Yendler -------------------------------------------------------------------------------- /algorithms/linked_lists/doubly_linked_list_exercise/exercise.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyendler/dbc-algorithms/7833218d3562e8937d5480dd89244b822e844830/algorithms/linked_lists/doubly_linked_list_exercise/exercise.md -------------------------------------------------------------------------------- /algorithms/linked_lists/prep.md: -------------------------------------------------------------------------------- 1 | ## Linked Lists Prep 2 | 3 | - Prelude: Only the basic section is really expected, but feel free to go onto to try harder things! 4 | - Skim through the Introduction chapter of CTC (Cracking the Coding Interview) 5 | - However, highly recommend to read through Introduction - Technical Questions (pgs 60-81) 6 | - DON'T READ LINKED LIST CHAPTER IN CRACKING THE CODE, at least, NOT YET. It explains right away how to write a LinkedList, so instead I recommend you hop over to [Exercism.io](http://exercism.io/exercises/ruby/simple-linked-list/readme) instructions and a Ruby test suite provided OR [Tutorials Point](https://www.tutorialspoint.com/data_structures_algorithms/linked_lists_algorithm.htm), basic rundown of LinkedList provided (although only look at the pseudocode if you have to!!) 7 | - Note: there are a couple of different ways to solve a linked list 8 | 9 | 10 | Basic (Look at above links, or find some Youtube videos): 11 | - write a basic linked list where you can push (insert link at back), pop (remove link at back), shift (remove link at front), unshift (insert link at front), and tell the size 12 | - understand what LIFO means (last in first out) and be able to draw it 13 | - convert an array to a LinkedList 14 | 15 | Not as basic: 16 | - insert specific node somewhere in the middle of a LinkedList 17 | - delete specifc node from the LinkedList (CTCI, pg 93) 18 | - delete node with a specific value 19 | - reverse the list 20 | - a few others from HackerRank: [Algo1](https://www.hackerrank.com/challenges/merge-two-sorted-linked-lists) [Algo2](https://www.hackerrank.com/challenges/compare-two-linked-lists) 21 | 22 | 23 | Really Not Basic (go back to Cracking the Code): 24 | - Return Kth from the Last (CTC Chapter 2, #2.2) 25 | - How do you tell if a LinkedList is circular or has an end? 26 | - Most of the problems in CTCI 27 | 28 | 29 | Further reading: 30 | - [good specs on what a LinkedList should do from Google Univeristy dude](https://github.com/jwasham/google-interview-university#linked-lists) 31 | - [some ruby book chapter I found](http://www.brpreiss.com/books/opus8/html/page96.html) 32 | - [some really indepth C Stanford stuff that goes into pointers and memory of linkedlists](http://cslibrary.stanford.edu/103/LinkedListBasics.pdf) 33 | -------------------------------------------------------------------------------- /algorithms/linked_lists/simple_linked_list_exercise/exercise.md: -------------------------------------------------------------------------------- 1 | ## Simple Linked List 2 | 3 | 4 | - size() - returns number of data elements in list 5 | - empty() - bool returns true if empty 6 | - value_at(index) - returns the value of the nth item (starting at 0 for first) 7 | - push_front(value) - adds an item to the front of the list 8 | - pop_front() - remove front item and return its value 9 | - push_back(value) - adds an item at the end 10 | - pop_back() - removes end item and returns its value 11 | - front() - get value of front item 12 | - back() - get value of end item 13 | - insert(index, value) - insert value at index, so current item at that index is pointed to by new item at index 14 | - erase(index) - removes node at given index 15 | - value_n_from_end(n) - returns the value of the node at nth position from the end of the list 16 | - reverse() - reverses the list 17 | - remove_value(value) - removes the first item in the list with this value 18 | -------------------------------------------------------------------------------- /algorithms/linked_lists/simple_linked_list_exercise/solutions/arf_solution.js: -------------------------------------------------------------------------------- 1 | var ARF_LinkedList; // This will namespace my constructor 2 | (function(){ 3 | function LinkedList(arrayOfValues) { 4 | var list = this; 5 | var current; 6 | (arrayOfValues || []).forEach(function(value){ 7 | var next = new Node(value); 8 | if(!current) { 9 | list.first = next; 10 | } else { 11 | current.next = next; 12 | } 13 | current = next; 14 | }); 15 | } 16 | 17 | function Node(value){ 18 | this.value = value; 19 | } 20 | 21 | LinkedList.prototype.size = function(){ 22 | var list = this; 23 | return count(list.first); 24 | 25 | 26 | function count(node){ 27 | if(!node) return 0; 28 | return 1 + count(node.next); 29 | } 30 | }; 31 | 32 | ARF_LinkedList = LinkedList; //assign constructor to lists 33 | })(); 34 | -------------------------------------------------------------------------------- /algorithms/linked_lists/simple_linked_list_exercise/solutions/hy_solution.js: -------------------------------------------------------------------------------- 1 | //note: I am using ES5 JS class syntactical sugar 2 | /* question: is there any difference, when using ES5 classes, between using constructor function this vs just using this in a function? ie: 3 | class Animal { 4 | constructor(name) { 5 | this.name = name 6 | } 7 | } 8 | 9 | vs 10 | 11 | function Animal (name) { 12 | this.name = name 13 | } 14 | */ 15 | 16 | 17 | class Link { 18 | constructor(value, link) { 19 | this._value = value; 20 | this._nextLink = link; 21 | } 22 | 23 | get nextLink() { 24 | return this._nextLink; 25 | } 26 | 27 | set nextLink(link) { 28 | this._nextLink = link 29 | } 30 | } 31 | 32 | class LinkedList { 33 | constructor() { 34 | this.head = null; 35 | this.tail = null; 36 | this.size = 0; 37 | } 38 | 39 | insertAtTail(value) { 40 | var link = new Link(value); 41 | if (this.size === 0) { 42 | this.head = link; 43 | this.tail = link; 44 | } else { 45 | var prevTail = this.tail; 46 | prevTail.nextLink = link; 47 | this.tail = link; 48 | } 49 | this.size += 1; 50 | } 51 | 52 | popTail() { 53 | var link = this.head 54 | 55 | while (link.nextLink != this.tail) { 56 | link = link.nextLink; 57 | } 58 | 59 | var returnLink = this.tail 60 | this.tail = link; 61 | link.nextLink = null; 62 | this.size -= 1 63 | return returnLink; 64 | } 65 | } 66 | 67 | var list = new LinkedList(); 68 | list.insertAtTail(1); 69 | list.insertAtTail(2); 70 | list.insertAtTail(3); 71 | 72 | console.log(list) 73 | console.log("-----") 74 | list.popTail(); 75 | console.log(list) -------------------------------------------------------------------------------- /algorithms/linked_lists/simple_linked_list_exercise/solutions/your_solution.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyendler/dbc-algorithms/7833218d3562e8937d5480dd89244b822e844830/algorithms/linked_lists/simple_linked_list_exercise/solutions/your_solution.js -------------------------------------------------------------------------------- /algorithms/linked_lists/simple_linked_list_exercise/tests/simple_linked_list_example.spec.js: -------------------------------------------------------------------------------- 1 | describe('ARF_LinkedList', function() { 2 | //this links the spec to my implementation, edit ARF_LinkedList to the name of your linked list constructor/object 3 | var LinkedList = ARF_LinkedList; 4 | 5 | var list; 6 | beforeEach(function(){ 7 | list = new ARF_LinkedList(); 8 | }); 9 | 10 | describe('.size', function () { 11 | it('should return 0 if there are no nodes', function() { 12 | expect(list.size()).toEqual(0); 13 | }); 14 | it('should return number of node if there are some nodes', function() { 15 | list = new ARF_LinkedList(['one']); 16 | expect(list.size()).toEqual(1); 17 | 18 | list = new ARF_LinkedList(['one', 'two']); 19 | expect(list.size()).toEqual(2); 20 | 21 | list = new ARF_LinkedList(['one', 'two', 'three']); 22 | expect(list.size()).toEqual(3); 23 | }); 24 | }); 25 | 26 | // Here you would continue to add more describe blocks for each of the functions listed in linked lists. 27 | }); 28 | -------------------------------------------------------------------------------- /algorithms/linked_lists/simple_linked_list_exercise/tests/test.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyendler/dbc-algorithms/7833218d3562e8937d5480dd89244b822e844830/algorithms/linked_lists/simple_linked_list_exercise/tests/test.rb -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration 2 | // Generated on Sun Feb 19 2017 10:48:51 GMT-0800 (PST) 3 | 4 | module.exports = function(config) { 5 | config.set({ 6 | 7 | // base path that will be used to resolve all patterns (eg. files, exclude) 8 | basePath: '', 9 | 10 | 11 | // frameworks to use 12 | // available frameworks: https://npmjs.org/browse/keyword/karma-adapter 13 | frameworks: ['jasmine'], 14 | 15 | 16 | // list of files / patterns to load in the browser 17 | files: [ 18 | 'algorithms/**/*.js', 19 | 'algorithms/**/*.spec.js' 20 | ], 21 | 22 | 23 | // list of files to exclude 24 | exclude: [ 25 | ], 26 | 27 | 28 | // preprocess matching files before serving them to the browser 29 | // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor 30 | preprocessors: { 31 | }, 32 | 33 | 34 | // test results reporter to use 35 | // possible values: 'dots', 'progress' 36 | // available reporters: https://npmjs.org/browse/keyword/karma-reporter 37 | reporters: ['progress'], 38 | 39 | 40 | // web server port 41 | port: 9876, 42 | 43 | 44 | // enable / disable colors in the output (reporters and logs) 45 | colors: true, 46 | 47 | 48 | // level of logging 49 | // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG 50 | logLevel: config.LOG_INFO, 51 | 52 | 53 | // enable / disable watching file and executing tests whenever any file changes 54 | autoWatch: false, 55 | 56 | 57 | // start these browsers 58 | // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher 59 | browsers: ['Chrome'], 60 | 61 | 62 | // Continuous Integration mode 63 | // if true, Karma captures browsers, runs the tests and exits 64 | singleRun: true, 65 | 66 | // Concurrency level 67 | // how many browser should be started simultaneous 68 | concurrency: Infinity 69 | }) 70 | } 71 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dbc-algorithms", 3 | "version": "1.0.0", 4 | "description": "A repo for organizing study session of the dbc-algorithms group.", 5 | "main": "index.js", 6 | "dependencies": { 7 | "karma": "^1.4.1" 8 | }, 9 | "devDependencies": { 10 | "jasmine-core": "^2.5.2", 11 | "karma": "^1.4.1", 12 | "karma-chrome-launcher": "^2.0.0", 13 | "karma-jasmine": "^1.1.0" 14 | }, 15 | "scripts": { 16 | "test": "./node_modules/karma/bin/karma start" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "git+https://github.com/hyendler/dbc-algorithms.git" 21 | }, 22 | "author": "Hanah Yendler", 23 | "license": "MIT", 24 | "bugs": { 25 | "url": "https://github.com/hyendler/dbc-algorithms/issues" 26 | }, 27 | "homepage": "https://github.com/hyendler/dbc-algorithms#readme" 28 | } 29 | --------------------------------------------------------------------------------