## Find an element that appears more than half the time (Typescript)

My solution to a “Daily Coding Problem” that I received in my mail today. Given a list of elements, find the majority element, which appears more than half the time (> floor(len(lst) / 2.0)). You can assume that such element exists. For example, given [1, 2, 1, 1, 3, 4, 0], Read more…

## Partition into two equal subsets problem (Typescript)

My solution to a “Daily Coding Problem” that I received in my mail today. Given a multiset of integers, return whether it can be partitioned into two subsets whose sums are the same. For example, given the multiset {15, 5, 20, 10, 35, 15, 10}, it would return true, since we Read more…

## Replace adjacent pixels in a 2-D matrix | Floodfill (Typescript)

My solution to a “Daily Coding Problem” that I received in my mail today. Given a 2-D matrix representing an image, a location of a pixel in the screen and a color C, replace the color of the given pixel and all adjacent same colored pixels with C. For example, given the Read more…

## Sublist sum problem (Typescript)

My solution to a “Daily Coding Problem” that I received in my mail today. Given a list of numbers L, implement a method sum(i, j) which returns the sum from the sublist L[i:j] (including i, excluding j). For example, given L = [1, 2, 3, 4, 5], sum(1, 3) should return sum([2, 3]), which is 5. You can assume that you can Read more…

## Prune Binary Tree to remove subtrees with 0 (Typescript)

My solution to a “Daily Coding Problem” that I received in my mail today. Given a binary tree where all nodes are either 0 or 1, prune the tree so that subtrees containing all 0s are removed. For example, given the following tree: 0 / \ 1 0 / \ 1 0 / \ Read more…