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…

Linkedlist pairwise swap (Typescript)

My solution to a “Daily Coding Problem” that I received in my mail today. Given the head of a singly linked list, swap every two nodes and return its head. For example, given 1 -> 2 -> 3 -> 4, return 2 -> 1 -> 4 -> 3. Here’s my solution in, Read more…

Nearest largest number to index i (Typescript)

My solution to a “Daily Coding Problem” that I received in my mail today. Given an array of numbers and an index i, return the index of the nearest larger number of the number at index i, where distance is measured in array indices. For example, given [4, 1, 3, 5, 6] and index 0, Read more…

Check if parenthesis are balanced problem with * (Typescript)

My solution to a “Daily Coding Problem” that I received in my mail today. You’re given a string consisting solely of (, ), and *. * can represent either a (, ), or an empty string. Determine whether the parentheses are balanced. For example, (()* and (*) are balanced. )*( is not balanced. Here’s my solution in Typescript, oneFortyTwo(str: string): boolean { if(str Read more…