package leetcode;

/**
 * https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix/
 */
public class Problem378 {
    public int kthSmallest(int[][] matrix, int k) {
        int rowSize = matrix.length;
        int colSize = matrix[0].length;
        int row = (k - 1) / rowSize;
        int col = (k - 1) - (row * colSize);
        // TODO
        return matrix[row][col];
    }

    public static void main(String[] args) {
        Problem378 prob = new Problem378();
        for (int i = 0; i < 9; i++) {
            System.out.println(prob.kthSmallest(new int[][]{
                {1, 5, 9},
                {10, 11, 13},
                {12, 13, 15}
            }, i + 1));
        }
    }
}

@@ -694,16 +694,413 @@
        %7D
+%0A%0A        for (int i = 0; i %3C 4; i++) %7B%0A            System.out.println(prob.kthSmallest(new int%5B%5D%5B%5D%7B%0A                %7B1, 2%7D,%0A                %7B1, 3%7D,%0A            %7D, i + 1));%0A        %7D%0A%0A        for (int i = 0; i %3C 4; i++) %7B%0A            System.out.println(prob.kthSmallest(new int%5B%5D%5B%5D%7B%0A                %7B1, 1, 1%7D,%0A                %7B1, 1, 3%7D,%0A                %7B1, 2, 3%7D,%0A            %7D, i + 1));%0A        %7D
 %0A    %7D%0A%7D

Update problem 378