Given an array arr that is a permutation of [0, 1, …, arr.length – 1], we split the array into some number of “chunks” (partitions), and individually sort each chunk. After concatenating them, the result equals the sorted array.
Month: January 2016
LeetCode -Toeplitz Matrix
A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element. Given a matrix, check if it is toeplitz. (Assume the matrix is not empty) Java Solution public boolean isToeplitzMatrix(int[][] matrix) { int m=matrix.length; int n=matrix[0].length; for(int i=0; i<m; i++){ for(int j=0; j<n; j++){ if(i+1<m && j+1<n && matrix[i][j]!=matrix[i+1][j+1]){ return false; … Read more
LeetCode – Number of Subarrays with Bounded Maximum (Java)
We are given an array A of positive integers, and two positive integers L and R (L <= R).
LeetCode – Rotated Digits (Java)
X is a good number if after rotating EACH digit individually by 180 degrees, we get a valid number that is different from X. A number is valid if each digit remains a digit after rotation. 0, 1, and 8 rotate to themselves; 2 and 5 rotate to each other; 6 and 9 rotate to each other, and the rest of the numbers do not rotate to any other number.