First Unique Character in a String - Leet Code Solution
Problem Statement Given a string, find the first non-repeating character in it…
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.
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;
}
}
}
}
The algorithm runs on O(n^2) in worst/average case.
Problem Statement Given a string, find the first non-repeating character in it…
Its a kind of incremental insertion technique, where the algorithm build up…
Max Priority Queue is a data structure which manage a list of keys(values). And…
System design interview is pretty common these days, specially if you are having…
Counting sort runs on relatively smaller set of input. Counting sort calculates…
Problem Statement Given a linked list, swap every two adjacent nodes and return…
Introduction In this post we will see following: How to schedule a job on cron…
Introduction There are some cases, where I need another git repository while…
Introduction In this post, we will see how to fetch multiple credentials and…
Introduction I have an automation script, that I want to run on different…
Introduction I had to write a CICD system for one of our project. I had to…
Introduction Java log4j has many ways to initialize and append the desired…