## LeetCode – Kth Smallest Element in a Sorted Matrix (Java)

Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.

Note that it is the kth smallest element in the sorted order, not the kth distinct element.

## Get Target Number Using Number List and Arithmetic Operations

Given a list of numbers and a target number, write a program to determine whether the target number can be calculated by applying “+-*/” operations to the number list? You can assume () is automatically added when necessary. An operator should be put between each two consecutive numbers. So each number has to be used.

For example, given {1,2,3,4} and 21, return true. Because (1+2)*(3+4)=21

## Top 10 API Related Questions from Stack Overflow

Stack Overflow is a large repository of valuable programming knowledge. Millions of questions have been answered on Stack Overflow and many answers have very high quality. This is the reason that Stack Overflow answers are often located on the top of the search result from Google.

## LeetCode – Lexicographical Numbers (Java)

Given an integer n, return 1 – n in lexicographical order. For example, given 13, return: [1,10,11,12,13,2,3,4,5,6,7,8,9]. Please optimize your algorithm to use less time and space. The input size may be as large as 5,000,000. Java Solution – DFS public List<Integer> lexicalOrder(int n) { int c=0; int t=n; while(t>0){ c++; t=t/10; }   ArrayList<Integer> … Read more

## LeetCode – Count Numbers with Unique Digits (Java)

Given a non-negative integer n, count all numbers with unique digits, x, where x is from 0 to 10^n-1. Java Solution public int countNumbersWithUniqueDigits(int n) { int[] arr = new int[n+1]; arr[0]=1; // x can be 0   for(int i=1; i<=n; i++){ arr[i]=9; for(int j=9; j>=9-i+2; j–){ arr[i] *= j; } }   int result … Read more

## LeetCode – Super Pow (Java)

Your task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array. Example1: a = 2 b = [3] Result: 8 Java Solution public int superPow(int a, int[] b) { int result=1;   for(int i=0; i<b.length; i++){ result … Read more

## Return a Stream vs. Return a Collection

Many Java API classes have methods that return a Collection. Since Java 8, methods can also return a Stream. Since the Stream is more flexible and efficient in many cases, should we return a Steam or Collection for our API methods?

## LeetCode – Kth Largest Element in an Array (Java)

Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For example, given [3,2,1,5,6,4] and k = 2, return 5. Note: You may assume k is always valid, 1 â‰¤ k â‰¤ array’s length. Java Solution 1 – Sorting … Read more

## LeetCode – PDF Update History (Java)

5/10/2016 1. Add about 20 more problems. 2. Optimize solutions for some old problems. 5/17/2016 1. Add 12 more problems. 2. Optimize solutions for some old problems. 3. Remove some naive solutions because they are too obvious and have no values. 8/1/2016 1. Add 30 more problems. 2. Optimize solutions for some old problems. 3. … Read more

## LeetCode – Palindrome Pairs (Java)

Given a list of unique words. Find all pairs of distinct indices (i, j) in the given list, so that the concatenation of the two words, i.e. words[i] + words[j] is a palindrome. Example 1: Given words = [“bat”, “tab”, “cat”] Return [[0, 1], [1, 0]] The palindromes are [“battab”, “tabbat”] Java Solution public List<List<Integer>> … Read more

## R hierarchical cluster data read from CSV file

The following code records how I load csv files to R and run hierarchical clustering algorithm on the data. I have to say that using R to plot the data is extremely EASY to do! > df <- read.csv("C:/Users/Creek/Desktop/data.txt", row.names=1,head=FALSE, sep=",") > d <- dist(as.matrix(df)) > hc <- hclust(d) > plot(hc) > q()> df <- … Read more

## Get the list of all public repositories from Github Using Java

You may want to dump all public repositories from Github. First you need to get the list of the names of repositories. The following code can do that for you. There is a limit of number of requests from one machine. So you may want to create a token first, to raise the limit, so … Read more

## Configure Kepler Eclipse for Java 8 on Mac

This post shows how to add Java 8 support to eclipse Kepler. You can following the 3 simple steps to get Java 8 work on your existing Kepler on Mac. 1. Install Java 8 To download Java SE Development Kit 8, select the correct version for Mac here. It is a .dmg file which can … Read more

## Install Pandas Without Root Access

If you want to install Pandas on Linux (Ubuntu, Redhat, etc.), but you don’t have root access, the installation may take a while. This is just record how I did it. After trying various kinds of different ways, I finally use one command to install it. Download Anaconda: http://continuum.io/downloads Change the download .sh file to … Read more

## Use LISTAGG() on multiple joined table in Oracle

You may know how to use LISTAGG() on a single table, but don’t know how to use LISTAGG on multiple joined tables. This example demonstrates how to use aggregate function on joined multiple tables in Oracle 12g. Assuming we have the following two tables. “User” Table ID Name 111 aaa 222 bbb 333 ccc “Record” … Read more