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
private static long[] ProductArray(int[] inputArray) | |
{ | |
int n = inputArray.Length; | |
long[] outputArray = new long[n]; | |
long[] leftToRight = new long[n]; | |
long[] rightToLeft = new long[n]; | |
// product left to right | |
leftToRight[0] = inputArray[0]; | |
for (int i = 1; i < n; 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
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Node node = new Node("root", new Node("left", new Node("left.left"), null), new Node("right")); | |
string serializedNode = node.Serialize(); | |
var deserializedNode = Node.Deserialize(serializedNode); | |
if (deserializedNode.Left.Left.Val != "left.left") | |
{ | |
throw new Exception("incorrect!"); |
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
class Program | |
{ | |
static readonly Dictionary<string, long> memoized = new Dictionary<string, long>(); | |
static void Main(string[] args) | |
{ | |
Console.WriteLine(CountDecode("111")); | |
} | |
private static long CountDecode(string s) | |
{ |
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
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Trie trie = new Trie(); | |
trie.Insert("dog"); | |
trie.Insert("deer"); | |
trie.Insert("deal"); | |
var foundWords = trie.Search("de"); |
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
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine(LongestSubstringWithKUniqueChars("abcba", 2)); | |
} | |
private static string LongestSubstringWithKUniqueChars(string s, int k) | |
{ | |
if (k == 0) |
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
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Tuple<long, double> tuple = CalculatePI(new Random(0)); | |
var points = tuple.Item1; | |
var pi = tuple.Item2; | |
Console.WriteLine($"PI: {pi} using Monte Carlo method with {points} points."); | |
} |
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
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
bool[][] matrix = new bool[][] | |
{ | |
new bool[] {false, false, false, false }, | |
new bool[] {true, true, false, true }, | |
new bool[] {false, false, false, false }, | |
new bool[] {false, false, false, false }, |
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
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine(PatternMatching("cheat", "c.*t")); // true | |
Console.WriteLine(PatternMatching("bcd", "abcd")); // false | |
Console.WriteLine(PatternMatching("cheat", "c.*te")); // false | |
Console.WriteLine(PatternMatching("abcdef", ".***************************.")); // true | |
Console.WriteLine(PatternMatching("abcdef", ".***************************")); // true | |
} |
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
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
int k = 24; | |
int[] s = new int[] { 12, 1, 61, 5, 9, 2 }; | |
s = s.Where(x => x <= k).ToArray(); | |
int n = s.Length; | |
List<int> indices = new List<int>(); |
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
class Program | |
{ | |
static int[] s; | |
static int k; | |
static Point[,] points; | |
static void Main(string[] args) | |
{ | |
k = 24; | |
s = new int[] { 12, 1, 61, 5, 9, 2 }; |
OlderNewer