Skip to content

Instantly share code, notes, and snippets.

View seemaullal's full-sized avatar

Seema Ullal seemaullal

  • United States
  • 00:56 (UTC -07:00)
View GitHub Profile
@seemaullal
seemaullal / CoDuels
Created March 17, 2015 22:33
CoDuels
### Core Features ###
- Log in
- Screen cast of what you can do (demo) for about page
- Live feed of open "battles" (___ & ___ are battling on ___ challenge).
- Panel? Github sign in, Google plus, twitter, other ??
- Profile page
- Random challenge plus challenge specific user
- Can pick any challenge (grouped by easy, medium, hard)
- Leader board on challenge page of "top scores" (?) from users who have done the challenge
- Let users comment/rate other peoples code (maybe)
@seemaullal
seemaullal / gist:04e7ea028e3c4acab8ad
Created April 27, 2015 20:16
Breadth First Search (for binary trees)
Note: This example is for a binary tree but for graphs, you do a similar thing but need to keep track of which nodes you have visited (until you visit all of them) and also add all children to the queue, not just the left and right child.
Tree:
5
/ \
2 6
/ \ / \
1 3 4 7
Add the root to the BFSArray (the results). Add its children to the queue.
@seemaullal
seemaullal / gist:3f5ef89bd9e62fbafaa5
Last active July 27, 2017 03:03
Async Library Notes

Some Useful Async library methods

async.each

async.each(arr, function(item,callback) {
	
},
function(err) { 
//function code that is to be done after the 2nd 
//argument of async.each is called on each element
@seemaullal
seemaullal / gist:dc9b81f8ee45cfa7eb83
Last active August 29, 2015 14:24
Algorithms 7/16

Level 1
Create a function called removeVowels() to remove all the vowels in a given string. Both uppercase and lowercase vowels should be removed. Your input will be a string and you should return the string without any vowels.

Level 2
Write a function that takes in a 2-D array that represents a square matrix and returns the product of the diagonal of the matrix. For example [ [ 2, 3], [ 4, 5] ] will return 10 (2x5).

Level 3

@seemaullal
seemaullal / gist:86ea817cc84e913fd4e9
Last active March 8, 2021 18:55
Minimum Coins for Change Solution

The first approach that jumps to mind for most people is using a greedy algoirthm- picking the biggest coin possible and continuing to do this until you have the amount you are looking for.

This looks something like this:

function minCoins(coinArr, amt) {
    var numCoins = 0;
    while (amt !== 0) {
        var eligibleCoins = coinArr.filter(function(coin) {
            return coin <= amt;
 });
@seemaullal
seemaullal / gist:be776dd3de4a03593ea0
Last active January 2, 2018 21:03
Sorting a Stack Without Additional Data Structures

Before you started coding, you should have tried to think about this problem visually. It would probably help to actually make a stack and then an empty helper stack and think about how you can move elements around until one of the stacks contains all the elements in sorted order.

Here is an explanation of how the solution works– this is just an explanation of the algorithm and contains no code (at one point the video says that 8 is smaller than 2 instead of 8 is bigger than 2 but the solution is still correct):


(click on the image to be taken to the video)

The general idea is that you always pop the top element of the stack which you are sorting. You want to add this to the helper stack but first need to make sure that doing so won't make the helper stack unsorted.

When all elements from the original stack are in the helper stack (i.e. the original stack is empty), you n

@seemaullal
seemaullal / gist:2d2c3493b5fe3a737264
Created July 14, 2015 18:45
Longest Common Subsring

A dynamic programming approach to this problem is described below. This approach takes O(n*n) time since we are comparing the letters of a string using an n*n matrix (where n is the length of the longer string since empty characters are added to the shorter string).

A dynamic programming approach to this problem is described below. This approach takes O(n*n) time since we are comparing the letters of a string using an n*n matrix (where n is the length of the longer string since empty characters are added to the shorter string).


(click on the image to be taken to the video)

Now that we know how to think about this programming from a dynamic programming perspective, we can write some code to solve the problem. There are a few different approaches to this but generally they all have some things in common:

  • you will have a 2-d array that represents the matrix which compares
@seemaullal
seemaullal / gist:c504de50ab42a57b59c1
Last active August 29, 2015 14:24
Valid Parentheses Combinations

One way of solving this problem is to do so recursively: -you can always pick a left parentheses as long as you haven't used up all of your left parentheses (i.e. if the # of left parentheses is less than n)

  • you can pick a right parentheses if it does not make the combination invalid
    • it will be invalid if there are more right parentheses than left
    • if you keep track of how many left parentheses you currently have added, then you can determine whether or not you can add a right parentheses to the current combination
    • when you have added n left parentheses and n right parentheses, you have a valid result and can add it to your results set

You can use the following recursive calls to mimic this.

First you call a function getCombinations(left,right,curr) with left = n, right =0, and curr='' because you have n left parentheses to add but can't add any right yet (it would make the combination invalid since right parentheses must come after a left) and your initial result is an empty stri

@seemaullal
seemaullal / gist:f8d2b47d036ff9b6308a
Last active August 29, 2015 14:25
Angular Sample #1
/*
This is a custom attribute directive I wrote. It was used for form validation to ensure that the name
entered in a form was not already in the database. It is an async custom validator.
*/
'use strict';
app.directive('sandwichnamevalidator', function(SandwichesFactory, $q){
return {
require: 'ngModel',
restrict: '',
// This is a state and the controller that corresponds to the state
'use strict';
angular.module('learndotApp')
.config(function ($stateProvider) {
$stateProvider
.state('calendar', {
url: '/calendar',
controller: 'CalendarCtrl',