Friedrich Ewald My Personal Website


  • Leetcode: Decode ways

    Characters can be encoded via different numbers. A -> 1, B -> 2, ..., Z -> 26. Given a string s of numbers, return the number of possible decodings. For example 12 can be decoded as A,B and as L.

    Continue reading

  • Leetcode: Reconstruct binary tree

    Given two lists of a preorder and inorder, create a tree and return the root node.

    preorder: [3,9,20,15,7]
    inorder:  [9,3,15,20,7]
    Resulting tree:
        /   \
       9    20
           /  \
          15   7
    The problem is not so obvious at first. If the preorder list would also contain null values for the places where the tree does not contain nodes, we could simply iterate over this list and reconstruct the tree from there. But since the null values are missing, we also need to take a look at the inorder list.

    Continue reading

  • Leetcode: Validate Binary Search Tree

    Given the root node of a tree, validate whether it is a valid Binary Search Tree. This is a tree where each node is unique, left children are smaller than the root and right children are greater than the root.

    Continue reading

  • Leetcode: Palindrome partitioning

    Given a string s, return a list containing of all possible partitions of that string that are palindromes. A palindrome is a string that is the same backwards as forwards. For example, abba is a palindrome. The string aab can be partitioned as follows: [['a','a','b'], ['aa','b']]. This is because a single character is by definition a palindrome.

    Continue reading

  • Leetcode: Remove element from list

    Given the head of a linked list, remove all items with val. Afterwards, return the new head.

    Continue reading

Page: 5 of 28