# 1295. Find Numbers with Even Number of Digits

1295. Find Numbers with Even Number of Digits

```class Solution {
public int countDigits(int num){
int count = 1;
while(num /10 !=0){
num = num /10;
count++;
}
return count;
}
public int findNumbers(int[] nums) {
int count = 0;
for (int i = 0; i < nums.length; i++){
if(countDigits(nums[i]) % 2 == 0) count++;
}
return count;
}
}
```

# 1200. Minimum Absolute Difference

1200. Minimum Absolute Difference

Brute Force: Time Limit Exceed

```class Solution {
public List<List> minimumAbsDifference(int[] arr) {
List<List> out = new ArrayList();
int minAbs = Integer.MAX_VALUE;
Arrays.sort(arr);
for (int i = 0; i < arr.length; i++){
for (int j= i+1; j < arr.length; j++){
minAbs = Math.min(minAbs, Math.abs(arr[i] - arr[j]));
}
}

for (int i = 0; i < arr.length; i++){
for (int j= i+1; j < arr.length; j++){
if(Math.abs(arr[i] - arr[j]) == minAbs) {
ArrayList pair = new ArrayList();
}
}
}
return out;
}
}
```

Easy Optimization:

```class Solution {
public List<List> minimumAbsDifference(int[] arr) {
List<List> out = new ArrayList();
int minAbs = Integer.MAX_VALUE;
Arrays.sort(arr);
//LinkedHashMap to preserve the insertion order
for (int i = 0; i  Math.abs(arr[i+1] - arr[i])){
minAbs = Math.abs(arr[i+1] - arr[i]);
index.put(i,i+1);
}
}

for (Integer a : index.keySet()){
ArrayList in = new ArrayList();
}
return out;
}
}
```

# 1337. The K Weakest Rows in a Matrix

1337. The K Weakest Rows in a Matrix

```class Solution {
private class Row{
int rowNum;
int soliders;
public Row(int rowNum, int soliders) {
this.rowNum = rowNum;
this.soliders = soliders;
}
public int getRowNum() {
return rowNum;
}
public void setRowNum(int rowNum) {
this.rowNum = rowNum;
}
public int getSoliders() {
return soliders;
}
public void setSoliders(int soliders) {
this.soliders = soliders;
}

}
public int[] kWeakestRows(int[][] mat, int k) {
int rowCount =0;
ArrayList rows = new ArrayList();
int i = 0;
for(i =0; i < mat.length; i++) {
rowCount =0;
for (int j = 0; j < mat[i].length; j++) {
if(mat[i][j] == 1) rowCount++;
}
}
Collections.sort(rows, new Comparator(){
@Override
public int compare(Row o1, Row o2) {
if (o1.getSoliders() == o2.getSoliders())
{
return  ((Integer)o1.getRowNum()).compareTo((Integer)o2.getRowNum());
}
return ((Integer)o1.getSoliders()).compareTo((Integer)o2.getSoliders());
}});
int[] out = new int[k];
for (int j = 0; j < out.length; j++) {
out[j] = rows.get(j).getRowNum();
}
return out;
}
}
```

# 1356. Sort Integers by The Number of 1 Bits

1356. Sort Integers by The Number of 1 Bits

```class Solution {
public int[] sortByBits(int[] arr) {
Integer[] arrObject = new Integer[arr.length];
for (int i = 0; i < arr.length; i++) {
arrObject[i] = arr[i];
}
Arrays.sort(arrObject, new Comparator() {

@Override
public int compare(Integer o1, Integer o2) {
if (countOnes(o1) == countOnes(o2))
return o1.compareTo(o2);
else if (countOnes(o1) > countOnes(o2))
return 1;
else
return -1;

}
});

for (int i = 0; i < arr.length; i++) {
arr[i] = arrObject[i];
}
return arr;
}

public static int countOnes(int n) {
int count = 0;
while (n != 0) {
n = n & (n - 1);
count++;
}
return count;
}
}
```

# 1207. Unique Number of Occurrences

1207. Unique Number of Occurrences

```class Solution {
public boolean uniqueOccurrences(int[] arr) {
HashMap h = new HashMap();
for(int i = 0; i < arr.length; i++) {
h.put(arr[i], h.getOrDefault(arr[i],0)+1);
}
if(h.size() == 0) return true;
HashSet repeats = new HashSet();

for (Integer a: h.keySet()) {
if(repeats.contains(h.get(a))) return false;