### Leetcode - Split a String Into the Max Number of Unique Substrings

Problem Statement Given a string s, return the maximum number of unique…

November 19, 2020

Given a Binary tree, print out nodes in level order traversal from left to right.

```
50
/ \
80 30
/ \ \
20 40 10
# Output
# 50 80 30 20 40 10
```

Use BFS (Breadth First Search) algorithm. Since, it reaches out to nodes first that are immediate neighbours.

Idea is to take a queue, keep accumulating queue for each child.

```
void bfs(Node node) {
Queue<Node> q = new Queue();
q.add(node);
while (!q.isEmpty()) {
Node n = q.pop();
print(n);
if (n.left != null) q.add(n.left);
if (n.right != null) q.add(n.right);
}
}
```

The `Complexity`

is `O(n)`

as we are visiting each nodes only once.

You can prepare a list of nodes at each level. We will also use DFS (Depth First Search) algorithm here.

```
void levelOrder(Node node, List<List<Node>> list, int level) {
if (node == null)
return;
List<Node> levelList = list.get(level);
if (levelList == null) {
levelList = new ArrayList();
list.add(levelList);
}
levelList.add(node);
levelOrder(node.left, list, level+1);
levelOrder(node.right, list, level+1);
}
List<List<Node>> list = new ArrayList();
levelOrder(root, list, 0);
```

After this, we can print the list.

The `Complexity`

is `O(n)`

as we are visiting each nodes only once.

Problem Statement Given a string s, return the maximum number of unique…

Counting sort runs on relatively smaller set of input. Counting sort calculates…

In this post, we will see some of the frequently used concepts/vocabulary in…

Problem Statement Given a non-empty array of integers, every element appears…

Problem Statement Given a linked list, swap every two adjacent nodes and return…

Problem The Leetcode file system keeps a log each time some user performs a…

Introduction In this post, we will explore some useful command line options for…

Introduction In this post, we will see how we can apply a patch to Python and…

Introduction We will list few interesting automation techniques with powershell…

Introduction We will introduce a Package Manager for Windows: . In automations…

Introduction In previous posts, we saw how to build FIPS enabled Openssl, and…

Introduction We will see how we can install Python from command line using pyenv…