### Valid Anagrams - Leet Code Solution

Problem Statement Given two strings s and t , write a function to determine if t…

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 two strings s and t , write a function to determine if t…

A Binary tree is a data structure which has two children nodes attached to it…

Problem Statement Given a signed integer, reverse digits of an integer. Return…

Young Tableau A a X b matrix is Young Tableau if all rows(from left to right…

Problem Statement There are two sorted arrays nums1 and nums2 of size m and n…

This topic is one of the most common studied. When somebody started preparation…

Introduction We have a page, for example a . And, upon submission we would want…

Problem Statement I have a parent component which loads some list categories…

Introduction This post is in contuation of our previous post: How to use Draft…

Introduction In this post, we will use in Next.js with strapi. And, we will…

Introduction In this post, we will integrate Next.js with Strapi fully. And we…

Introduction Next-auth is a fantastic library for abstracting handling of…