### Rotate Image - Leet Code Solution

Problem Statement You are given an n x n 2D matrix representing an image, rotate…

May 16, 2019

This is kind of preliminary technique of sorting. And, this is the first algorithm that a beginner learns.

In this algorithm, we iterate over the array, and compare two consecutive numbers. And, if first is larger, then swap it.
And, we keep on doing this till end.
So, the **Bubble** here is the biggest element which we keep on swapping.

- We start with two loops. Outer loop just goes from 0 to last-1 index.
- Inner loop always starts frmo 0-index, and goes till n-1 each time.
- On first iteration, we got the biggest element at the end of the array.
- Next iteration goes till n-1 elements. Since, we already sorted the largest element at the end.
- We keep on pushing the largets element from remaining n-1 array.

See the code here:

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

- 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 You are given an n x n 2D matrix representing an image, rotate…

A number consists of digits. Example: 843. Its a 3-digit number. Radix sort…

Its every software engineer’s dream to work with the big FAANG companies…

Problem Statement Given a string, find the length of the longest substring…

Graph Topological Sorting This is a well known problem in graph world…

Min Priority Queue is a data structure which manage a list of keys(values). And…

Introduction I was trying to upload images to my backend using rest APIs. I was…

Introduction In this post, we will see multiple ways to use annotation…

Introduction I was using Paypal payment on one of my website, and suddenly lot…

Introduction In a Spring boot app, we tend to use annotation, so that Spring…

Introduction In this posr, we will see how to prepare mysql query to fetch user…

Introduction Here, we will see the drupal code to fetch all the active users…