# Programming

## Advent of Code F# — Day 13

ps. look out for all my oth­er solu­tions for Advent of Code chal­lenges here.   Day 13 See details of the chal­lenge here. Today’s chal­lenge involves solv­ing two sep­a­rate prob­lems: count­ing set bits in an inte­ger lev­el order tree tra­ver­sal For the first prob­lem, I rec­om­mend read­ing through this blog post which cov­ers sev­er­al approach­es and opti­miza­tions for this …

## Equilibrium Index problem in F#

A good friend point­ed me to a nice cod­ing chal­lenge she encoun­tered — find­ing the Equi­lib­ri­um Index of an array in O(n) time. After a quick dis­cus­sion we end­ed up with 2 solu­tions, and nat­u­ral­ly I had to code them up in F#   Solu­tion 1 This is the same approach to the one you saw in …

## Advent of Code F# — Day 12

ps. look out for all my oth­er solu­tions for Advent of Code chal­lenges here.   Day 12 See details of the chal­lenge here. The input for today’s chal­lenge looks like this: cpy 1 a cpy 1 b cpy 26 d jnz c 2 jnz 1 5 cpy 7 c … This is very sim­i­lar to Day 23 …

## Advent of Code F# — Day 11

ps. look out for all my oth­er solu­tions for Advent of Code chal­lenges here.   Day 11 See details of the chal­lenge here. Today is per­haps the first AOC chal­lenge that is real­ly chal­leng­ing and required a lot of thought, and I real­ly enjoyed it! First, let’s mod­el the prob­lem domain. and we’ll need a way to …

## Implementing a BST in F#

Bina­ry Search Trees (BST) seem to be a hot top­ic in tech­ni­cal inter­views. So, in order to help me pre­pare for all these grilling tech­ni­cal tests, I thought I’d give it a crack at imple­ment­ing inser­tion, dele­tion and ver­i­fi­ca­tion log­ic since I’ve already done both breath-first and depth-first tra­ver­sals.   Ver­i­fi­ca­tion Start­ing with some­thing nice and …

## Depth-First Tree Traversal in F#

We looked at breath-first tree tra­ver­sal ear­li­er today, now let’s take a look at depth-first tree tra­ver­sal as well. Here, we loop through the tree start­ing with the root, yield the val­ue for each of the nodes before recur­sive­ly tra­vers­ing down all the left branch first and then the right branch.   Try it Your­self   Links Breath-First …

## Level Order Tree Traversal in F#

Anoth­er com­mon prob­lem I see dur­ing my prepa­ra­tion for tech­ni­cal inter­views is the Lev­el Order Tree Tra­ver­sal (or Breadth-First) prob­lem. I always like to think with my F# hat on when I solve algo­rithm prob­lem, so here’s an imple­men­ta­tion in F# . Here we have a nest­ed recur­sive loop func­tion that: yields the val­ue from the nodes …

## Advent of Code F# — Day 10

ps. look out for all my oth­er solu­tions for Advent of Code chal­lenges here.   Day 10 See details of the chal­lenge here. The input for today’s chal­lenge looks like this: bot 171 gives low to bot 4 and high to bot 84 bot 1 gives low to bot 117 and high to bot 81 bot 82 …

## Advent of Code F# — Day 9

ps. look out for all my oth­er solu­tions for Advent of Code chal­lenges here.   Day 9 See details of the chal­lenge here. The input for today’s chal­lenge is a very long string like this: (6x9)JUORKH(10x13)LNWIKDMACM(126x14)(21x8)QLKUJNVVZIQGGFCJZMPHK(2x1)ZH(59x3)(38x14)KELEPIDYLCGJUBCXACRSOCEZYXLO… First, let’s see how we’re gonna parse this input. The approach I went with is to recur­sive­ly split the input …

## O(n) solution to Multiply Others problem in F#

Anoth­er tasty chal­lenge that I ran into dur­ing my prepa­ra­tion for tech­ni­cal inter­views is this seem­ing­ly sim­ple prob­lem from Face­book. input [2,3,1,4] out­put [12,8,24,6] Mul­ti­ply all fields except it’s own posi­tion. Restric­tions: 1. no use of divi­sion 2. com­plex­i­ty in O(n) The main chal­lenge is in mak­ing the algo­rithm run in O(n) time. One solu­tion I …