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.

Sort Characters by Frequency

In this tutorial, I am going to discuss a very interesting problem sort characters by frequency.

Given a string, write a method to sort it in decreasing order based on the frequency of characters.

For example:

Example 1

Input : “teee”

Output: “eeet”

Example 2:

  Input: “dddbbb”

Output: “dddbbb”   or “bbbddd” (Both d and b appear 3 times so any of the above output are valid)

  Example 3:

  Input:  “Eett”

Output: “ttEe” or “tteE”  (Both e and E are two different characters so the output should not be “Eett”)

Check whether Two Strings are Anagram of each other

Given two strings, write a code to check whether two strings are anagram of each other or not. In this tutorial, I am going to discuss multiple approaches and their java implementation to check if two strings are anagrams or not.

Let’s first understand what is an anagram? and how we are going to solve this problem.

What is an Anagram?

Two strings are said to be anagrams of each other if it contains the same characters, only the order of characters in both the strings is different. In other words, both strings must contain the same exact letters in the same exact frequency.