Skip to content

Instantly share code, notes, and snippets.

View VegaFromLyra's full-sized avatar

Asha Balasubramaniam VegaFromLyra

View GitHub Profile
@VegaFromLyra
VegaFromLyra / randomSample
Created July 15, 2015 20:39
Reservoir Sampling
using System;
// Given a stream of numbers, return a set of k (fixed) numbers from it uniformly at random.
// Also, prove that your solution is actually uniformly random.- https://en.wikipedia.org/wiki/Reservoir_sampling
namespace ReservoirSampling
{
public class Program
{
public static void Main(string[] args)
@VegaFromLyra
VegaFromLyra / coins
Last active August 29, 2015 14:24
Coins
using System;
using System.Collections.Generic;
using System.Linq;
namespace MinimumCoins
{
public class Program
{
public static void Main(string[] args)
{
@VegaFromLyra
VegaFromLyra / HashMap.cs
Last active August 29, 2015 14:24
Generic Hash Map
using System;
using System.Collections.Generic;
namespace HashMapImplementation
{
public class Program
{
public static void Main(string[] args)
{
int n = 5;
@VegaFromLyra
VegaFromLyra / slidingMinimum
Created July 13, 2015 00:02
Sliding minimum
using System;
using System.Collections.Generic;
// Given a sequence of integers and a size k,
// print the minimum number for every sliding window of size k
namespace SlidingMinimum
{
public class Program
{
@VegaFromLyra
VegaFromLyra / Main.cs
Created July 12, 2015 05:17
Simulate traffic light system
using System;
namespace TrafficLights
{
public class Program
{
public static void Main(string[] args)
{
var trafficLightController = TrafficLightController.getInstance();
Console.WriteLine("Press Ctrl C to stop");
@VegaFromLyra
VegaFromLyra / maximumMushrooms
Created July 10, 2015 16:52
Mushroom picker
using System;
// https://codility.com/media/train/3-PrefixSums.pdf
namespace MushroomPicker
{
public class Program
{
public static void Main(string[] args)
{
using System;
// An array of integers of size n is represented by a forest aka a collection of trees.
// The tree is a n-ary tree and has the property that the parent's value is always smaller
// than its children
// Given these conditions, write a method to delete a number from this array given an index.
// This should also re-arrange the forest
// Value of each node is an index in the array
// Root nodes have the value -1
// Child nodes have the parent as the value
@VegaFromLyra
VegaFromLyra / stitchingStrings
Last active August 29, 2015 14:24
Coding challenge
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Linq;
// Question:
// We've taken some strings and chopped them up into pieces at random spots, then we're rearranged them and stuck them back together!
// Your goal is to write some code that turns that process backwards.
@VegaFromLyra
VegaFromLyra / DataCenters
Created July 2, 2015 00:34
Data centers
using System;
using System.Collections.Generic;
using System.Linq;
// Oh no! Disaster has struck some of ACME's redundant data centers. The administrators have managed to restore backups, but some data sets are still missing from some data centers. Fortunately, every data set can be found at least once in one or more of the data centers. However, before ACME can resume normal operations, it needs to ensure that each data center has a copy of every data set.
//
// Your goal is to help ACME resume normal operations by writing a program to synchronize data sets between data centers using as few copies as possible.
//
//
//
@VegaFromLyra
VegaFromLyra / Sort
Created July 1, 2015 18:01
Sort words and numbers
using System;
using System.Collections.Generic;
// Given a string containing a combination of words and numbers, sort the string
// such that the words and numbers maintain their position in the string
// Input: car 2 bus 1
// Output: bus 1 car 2
namespace SortWordsAndNumbers