Maximum Length of Subarray With Positive Product - Leet Code Solution
Problem Statement Maximum Length of Subarray With Positive Product. Given an…
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 Maximum Length of Subarray With Positive Product. Given an…
In this post, we will see some of the frequently used concepts/vocabulary in…
A Binary tree is a data structure which has two children nodes attached to it…
System design interview is pretty common these days, specially if you are having…
Problem Statement Given a string s, return the maximum number of unique…
In this post, we will see some of the frequently used concepts/vocabulary in…
System design interview is pretty common these days, specially if you are having…
Introduction You are given an array of integers with size N, and a number K…
Graph Topological Sorting This is a well known problem in graph world…
Problem Statement Given a Binary tree, print out nodes in level order traversal…
Problem Statement Given an array nums of n integers and an integer target, are…