Solution to 105. Construct Binary Tree from Preorder and Inorder Traversal problem on LeetCode.
This file contains 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
defmodule Fib do | |
defmodule MLibby do | |
def number(n) do | |
[head | _] = _sequence(n) | |
head | |
end | |
def sequence(n), do: Enum.reverse(_sequence(n)) | |
defp _sequence(0), do: [0] | |
defp _sequence(1), do: [1, 0] |
This file contains 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
# example input | |
["+3", "+3", "+4", "-2", "-4"] | |
|> Enum.map(&String.to_integer/1) | |
|> Stream.cycle() | |
|> Enum.reduce_while({0, MapSet.new([0])}, fn n, {sum, seen} -> | |
new_sum = sum + n | |
if MapSet.member?(seen, new_sum) do | |
{:halt, new_sum} | |
else |
Given a Fibonacci number, give the previous Fibonacci number. If the number given is not a Fibonacci number, return -1.
From rendezvous with cassidoo, April 4 2022 "Interview Question Of The Week"
Given two strings n and m, return true if they are equal when both are entered into text editors. But: a # means a backspace character (deleting backwards), and a % means a delete character (deleting forwards).
This file contains 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 Either | |
def self.pure(value) | |
Right.new(value) | |
end | |
class Left | |
def initialize(left) | |
@left = left | |
end |
This file contains 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
POINTS = { | |
"A" => 1, "B" => 3, "C" => 3, "D" => 2, | |
"E" => 1, "F" => 4, "G" => 2, "H" => 4, | |
"I" => 1, "J" => 8, "K" => 5, "L" => 1, | |
"M" => 3, "N" => 1, "O" => 1, "P" => 3, | |
"Q" => 10, "R" => 1, "S" => 1, "T" => 1, | |
"U" => 1, "V" => 4, "W" => 4, "X" => 8, | |
"Y" => 4, "Z" => 10 | |
} |
This file contains 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
require "sequel" | |
DB = Sequel.postgres("sequel_test") | |
DB.create_table? :items do | |
primary_key :id | |
String :name | |
Float :price | |
end |
I hereby claim:
- I am madlep on github.
- I am madlep (https://keybase.io/madlep) on keybase.
- I have a public key whose fingerprint is 6A92 159D 5E40 7094 FABE B73A 0B4D 44BE 816C C67C
To claim this, I am signing this object:
This file contains 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
defmodule Foobar do | |
defstruct :my_field, :another_field | |
def do_a_thing_destructure(%Foobar{my_field: mf, another_field: af}) do | |
something_else(mf, af) | |
end | |
def do_a_thing_struct_access(foobar = %Foobar{}) do | |
something_else(foobar.my_field, foobar.another_field) | |
end |
NewerOlder