This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public boolean hasValidPath(char[][] grid) { | |
int m = grid.length; | |
int n = grid[0].length; | |
int[][] ref = new int[m][n]; | |
for(int i = 0; i < m; i++) { | |
for(int j = 0; j < n; j++) { | |
if(grid[i][j] == '(') { | |
ref[i][j] = 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int largestCombination(int[] candidates) { | |
int min = Integer.MAX_VALUE; | |
int max = Integer.MIN_VALUE; | |
for(int i = 0; i < candidates.length; i++) { | |
min = Math.min(min, candidates[i]); | |
max = Math.max(max, candidates[i]); | |
} | |
while((min & min - 1) > 0) { | |
min &= min - 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Total time complexity O(n), space complexity is O(k) | |
public class findMoreThanKthLargest { | |
public static void main(String[] args) { | |
int[][] example = new int[][]{{1426828011, 9}, | |
{1426828028, 350}, | |
{1426828037, 25}, | |
{1426828056, 231}, | |
{1426828058, 109}, | |
{1426828066, 111}}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//dijkstra TLE | |
public int minimumObstacles(int[][] grid) { | |
//dijkstra | |
int[][] ref = new int[][]{{-1,0}, {1,0}, {0,-1}, {0,1}}; | |
int[][] minDistance = new int[grid.length][grid[0].length]; | |
for(int[] e: minDistance) { | |
Arrays.fill(e, Integer.MAX_VALUE); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public boolean canPartitionKSubsets(int[] nums, int k) { | |
int sum = 0; | |
int max = 0; | |
for(int e: nums) { | |
sum += e; | |
max = Math.max(max, e); | |
} | |
if(sum % k > 0 || max > (sum / k)) return false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MinEmptySpaceInChessboard { | |
/** | |
* From Google: | |
* Given n * n chessboard and pos array means position (i, j) has chess. | |
* Calculate min distance from each chess to the empty space. | |
* ex: n = 3, pos = {{0, 0}, {0, 1}, {0, 2}, {1, 1}, {1, 2}, {2, 0}} | |
* ans: [1, 2, 2, 1, 1, 1] | |
* | |
* follow up: if n = ∞ , pos has just few chess. How to improve? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html style="background-color:#F6F7FC;"> | |
<head> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<style> | |
/* width */ | |
::-webkit-scrollbar { | |
width: 10px; | |
} | |
OlderNewer