Skip to content

Instantly share code, notes, and snippets.

View hsaputra's full-sized avatar

Henry Saputra hsaputra

View GitHub Profile
/**
Given a 2D board and a word, find if the word exists in the grid.
The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once.
Example:
board =
[
['A','B','C','E'],
class Solution {
public int mySqrt(int x) {
if (x == 1 || x == 0) {
return x;
}
long low = 1;
long high = x;
// Need to use binary search to fix y such that y*y = x
class Solution {
public List<List<String>> groupAnagrams(String[] strs) {
if (strs == null || strs.length == 0)
return new LinkedList<List<String>>();
Map<String, List<String>> superAnagrams = new HashMap<>();
int sLen = strs.length;
for (String str : strs) {
class Solution {
public int lengthOfLongestSubstring(String s) {
// check for invalid arguments.
if (s == null || s.length() == 0) {
return 0;
}
if (s.length() == 1) {
return 1;
}
class Solution {
public int[] twoSum(int[] nums, int target) {
// Tests:
// 1. Empty array
// 2. 1 element
// 3. Negative vs positive
// Exactly One solution
if (nums == null || nums.length == 0) {
return null;
class Solution {
public List<List<Integer>> threeSum(int[] nums) {
// test cases
// nums invalid
// no duplicates
// sums to zero
// Eg: [-1,0,1,2,-1,-4]
@hsaputra
hsaputra / gist:fea6a827cb022c14ac836a44429f7006
Last active October 9, 2018 04:02
Phone number combo - interview
class Solution {
public List<String> letterCombinations(String digits) {
if (digits == null || digits.length() == 0)
return new LinkedList<String>();
// local vars
Map<Integer, String> digitsToChars = new HashMap<Integer, String>();
digitsToChars.put(0, "");
digitsToChars.put(1, "");
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {

Keybase proof

I hereby claim:

  • I am hsaputra on github.
  • I am hsaputra (https://keybase.io/hsaputra) on keybase.
  • I have a public key ASD0idJfHyDoq7izryOpBTVGgE3glrToRwSe5Y6gkQsbYgo

To claim this, I am signing this object:

@hsaputra
hsaputra / gist:414106aafd75eb143025570905c8972c
Last active September 22, 2017 23:08
Example Device Plugin
https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/deviceplugin/device_plugin_stub.go
https://github.com/GoogleCloudPlatform/container-engine-accelerators/blob/master/cmd/nvidia_gpu/nvidia_gpu.go
https://github.com/vikaschoudhary16/kubernetes/pull/7/files