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

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

May 15, 2019

It is one of a simple algorithm to study for a beginner to understanding sorting algorithms.

In this algorithm, we start with 0th index value. We compare it in whole array to find if any other number is smaller than this. So effectively, we find the minimum number through rest of the array from our starting index.

And, we swap the numbers of the initial number and the smalles number found in array.

- We start with two loops. Outer loop gives inner loop the index of array to start with.
- Inner array start with the index that outer loop gave.
- Inner loop finds the minimum number
- Swap the indexes, if found the smaller number
- Inner loop breaks, Outer loop move ahead.
- So, we left the smallest number found so far in beginning. And, sort rest of the array

See the code here:

```
public void sort(int[] arr) {
int l = arr.length;
for (int i=0; i<l-1; i++) {
int smallestNumIndex = i;
for (int j=i+1; j<l; j++) {
if (arr[smallestNumIndex] > arr[j]) {
smallestNumIndex = j;
}
}
if (i != smallestNumIndex) {
//swap
int temp = arr[i];
arr[i] = arr[smallestNumIndex];
arr[smallestNumIndex] = temp;
}
}
}
```

- Its an in-place sorting algorithm
- Performance is usually worse than Insertion sort
- Applicable for small set of input only
- Its very simple algorithm

The algorithm runs on O(n^2) in worst/average case.

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

Problem Statement Roman numerals are represented by seven different symbols: I…

Problem Statement Given an array, rotate the array to the right by k steps…

Its a tree based data structure which is a complete binary tree(all nodes have…

A Binary Search tree (BST) is a data structure which has two children nodes…

Problem Statement Replace all spaces in a string with ‘%20’ (three characters…

Problem Statement You are given a string text of words that are placed among…

Problem Statement You are given a rows x cols matrix grid. Initially, you are…

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

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

Problem Statement Replace all spaces in a string with ‘%20’ (three characters…

Problem Implement an algorithm to determine if a string has all the characters…