Right View of a Binary Tree

Given a binary tree, we have to write a code to print the right view of a binary tree.

Right View of a Binary Tree

The right view of a binary tree is the set of visible nodes when it is visited or seen from the right side.

For example:

Example 1:

Let’s take an example. In this binary tree, the node which is visible from the right side is 1, 3, 4, and 8.

Find Triplets with Zero Sum (3Sum Problem)

Find triplets with zero sum (3Sum Problem). Given an array of integers, write a code to find all unique triplets in the array which gives the sum of zero.

Note: The solution set must not contain duplicate triplets.

For example –

Example 1:

Input: {-1, 0, 1, 2, -1, -4}

Output: {-1, 0, 1}, {-1, -1, 2}

Example 2:

Input: {-8, -7, 5, 2}

Output: {-7, 5, 2}

Longest Substring Without Repeating Characters

Given a string s, find the length of the longest substring without repeating characters.

For example –

Example 1:

Input: “abcabcbb” Output: 3

The output string is “abc”, with a length of 3.

Example 2:

Input: “bbbbb” Output: 1

The longest substring in this example is “b”. Its length is 1.

Example 3:

Input: “pwwkew” Output: 3

The answer is “wke”. Its length is 3.