Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created January 22, 2018 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/2c9a9cbbfd8f8a06008351d5c406089e to your computer and use it in GitHub Desktop.
Save jianminchen/2c9a9cbbfd8f8a06008351d5c406089e to your computer and use it in GitHub Desktop.
Word count exercise - 30 minutes mock interview practice - I need to work on the solution after the mock interview
using System;
class Solution
{
internal class Bucket{
public ListOfWords = new List<string>;
public Bucket(
{
ListOfWords = new List<string>();
}
}
public static string[,] WordCountEngine(string document)
{
if(document == null || document.Length == 0)
{
return new string[0,0];
}
var processed = String.ToLower(document);
// replace
processed = processed.Replace('\\','\0');
// split the words
var words = processed.Split(" ,!");
// sorted the
}
/// comparison sort -> nlogn -
/// bucket sort -> detmine max value -> 1 to max buckets -> go over each word
/// const size of bucket -> hint at most 200
private static string[][] applyBucketSort(Dictionary<string, int> dict)
{
// get maximum value count
var max = 0;
foreach(var pair in dict)
{
var number = pair.Value;
max = number > max ? number : max;
}
// var list = new List<string>
var buckets = new Bucket[max];
for(int i = 0 ; i < max; i++)
{
buckets[i] = new Bucket();
}
// continue after mock interview, 30 minutes time out
}
private static Dictionary<string, int> storeToDict(string[] words)
{
var dict = new Dictionary<string, int>();
foreach(var word in words)
{
if(!dict.ContainsKey(word))
{
dict.Add(word, 1);
}
else
{
dict[word]++;
}
}
return dict;
}
static void Main(string[] args)
{
}
}
/*
constraints: lower case/ upper case -> lower case
delimiter at least ". !"
sorted by descending order, number of occurrences
if ascending order apping to same occurrence
replace - punctuation 'you'll' with whitespace ""?
Time complexity: linear time complexity - >
sorting O(nlogn)
counting - bucket O(n) - number of bucket
Space complexity
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment