随笔分类 - Coding Test
Amazon | OA 2019 | Optimal Utilization
摘要:2-Pointers Syntax side: Pay attention to how to print an array: System.out.println(Arrays.toString(int[] item));
阅读全文
Pocket Gem OA: Log Parser
摘要:涉及到处理Date, 以及STDIN from a file 处理Date可以用SimpleDateFormat这个class static Date parseTime(String timeStr) { Date time = new Date(); DateFormat dft = new S
阅读全文
2Sigma OA prepare: Longest Chain
摘要:DP use HashMap: 根据string的长度sort,然后维护每个string的longest chain,default为1,如果删除某个char生成的string能提供更长的chain,则更新
阅读全文
2Sigma OA prepare: Friends Circle
摘要:DFS & BFS: 关键在于构造graph 如果想把String[] array转化为2d char array, code如下,写的时候这里出了点小问题。friends是String[] Union Find
阅读全文
Twitter OA prepare: Two Operations
摘要:准备T家OA,网上看的面经最直接的方法,从target降到1,如果是奇数就减一,偶数就除2 1 public static void main(String[] args) { 2 int a = shortest(17); 3 System.out.println(a)...
阅读全文
Twitter OA prepare: even sum pairs
摘要:思路:无非就是扫描一遍记录奇数和偶数各自的个数,比如为M和N,然后就是奇数里面选两个、偶数里面选两个,答案就是M(M-1)/2 + N(N-1)/2
阅读全文
Twitter OA prepare: K-complementary pair
摘要:2sum的夹逼算法,需要sort一下。本身不难,但是tricky的地方在于允许同一个数组元素自己跟自己组成一个pair,比如上例中的[5, 5]。而且数组本身就允许值相等的元素存在,在计算pair时,算成不同的pair,比如数组是[3,3],K=6,这时的pair有[0, 0], [0, 1], [...
阅读全文
Twitter OA prepare: Anagram is A Palindrome
摘要:Algorithm:Count the number of occurrence of each character.Only one character with odd occurrence is allowed since in a palindrome maximum number of c...
阅读全文
Twitter OA prepare: Visit element of the array
摘要:分析:就是建立一个boolean array来记录array里面每个元素的访问情况,遇到访问过的元素就停止visiting,返回未访问的结点个数 1 public int visiting(int[] A, int N) { 2 if (A==null || A.length==0) ret...
阅读全文
VMware Coding Challenge: The Heist
摘要:类似BackpackII问题 1 static int maximize_loot(int[] gold, int[] silver) { 2 int[][] res = new int[gold.length+silver.length+1][10001]; 3 ...
阅读全文
VMware Coding Challenge: Removing Duplicates Entries
摘要:1 static LinkedListNode removeDuplicates(LinkedListNode list) { 2 LinkedListNode cur = list; 3 HashSet set = new HashSet(); 4 ...
阅读全文
VMware coding Challenge: Coin Toss Betting
摘要:1 static int CoinTossEndAmount(int betAmount, String coinTossResults) { 2 if (betAmount <=0 || coinTossResults.length() == 0) return betA...
阅读全文
Amazon OA
摘要:Remove Duplicates from unsorted array,它的错误在于9-10行k out of bound,改成下面这样就没问题了 1 public class removeDuplicates { 2 public static int[] remove(int[] a...
阅读全文
VMware coding Challenge:Date of Weekday
摘要:这道题再次证明了这种细节的题目,画个图容易搞清楚 1 import java.util.Scanner; 2 3 4 public class Solution2 { 5 static int DateOfWeekday(int date, int weekday) { 6 ...
阅读全文
VMware Coding Challenge: Possible Scores && Summary: static
摘要:Combination Sum I 那道题的变体 1 /* 2 * Complete the function below. 3 */ 4 5 static int is_score_possible(int score, int[] increments) { 6 A...
阅读全文
Twitter OA prepare: Rational Sum
摘要:In mathematics, a rational number is any number that can be expressed in the form of a fraction p/q , where p & q are two integers, and the denominato...
阅读全文
Twitter OA prepare: Flipping a bit
摘要:You are given a binary array with N elements: d[0], d[1], ... d[N - 1]. You can perform AT MOST one move on the array: choose any two integers [L, R],...
阅读全文