Skip to content

Instantly share code, notes, and snippets.

View m-khooryani's full-sized avatar

Mojtaba Khooryani m-khooryani

  • Polestar
  • Gothenburg, Sweden
View GitHub Profile
@m-khooryani
m-khooryani / Program.cs
Created June 4, 2020 19:03
Count Possible Decoding
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)
{
@m-khooryani
m-khooryani / Program.cs
Created June 3, 2020 11:16
De/Serialize Binary Tree
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!");
@m-khooryani
m-khooryani / Program.cs
Last active June 3, 2020 10:54
Product Array
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++)