Tag: swift

  • Same Tree with Swift

    Problem: Given two binary trees, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally identical and the nodes have the same value. Solution Using Breadth-First Search traverse trees and compare nodes during traversal. /** * Definition for a binary tree node.…

  • Count the number of ways to traverse a Matrix in Swift

    Question: Count the number of ways to traverse a from the top left corner to the bottom, right corner. Limitation: we can only move down or right. Few solutions: first one brute force and second dynamic programming and measuring their time execution below. To compute 10 x 10 matrix with recursive brute force took 1.4…