随笔分类 - Algorithm
摘要:Given 2 integers u and v, find the shortest array such that bitwise-xor of its elements is u, and the sum of its elements is v. Input The only line co
阅读全文
摘要:Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must
阅读全文
摘要:Primitive Primes : two integers are coprime if their GCD is 1. If a number A is not divisible by another prime number P, then A and P are guranteed to
阅读全文
摘要:Given a m x n grid. Each cell of the grid has a sign pointing to the next cell you should visit if you are currently in this cell. The sign of grid[i]
阅读全文
摘要:An interesting problem using suffix sum. For each wrong tries that is correct until after index p[i], we add 1 to cnt[p[i]]. This represents that all
阅读全文
摘要:Problem Statement Link Clarification: The problem states that for each pair of points, we consider the minimum possible distance over any possible mom
阅读全文
摘要:Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that su
阅读全文
摘要:We are given an array A of N lowercase letter strings, all of the same length. Now, we may choose any set of deletion indices, and for each string, we
阅读全文
摘要:You have some sticks with positive integer lengths. You can connect any two sticks of lengths X and Y into one stick by paying a cost of X + Y. You pe
阅读全文
摘要:Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) Yo
阅读全文
摘要:Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two
阅读全文
摘要:Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two
阅读全文
摘要:You are given coins of different denominations and a total amount of money. Write a function to compute the number of combinations that make up that a
阅读全文
摘要:Given a linear equation of n variables, find the total number of non-negative integer solutions of it. All coefficients are positive. Example: input:
阅读全文
摘要:You are given a series of arithmetic equations as a string, such as: y = x + 1 5 = x + 3 10 = z + y + 2 The equations use addition only and are separa
阅读全文
摘要:(This problem is an interactive problem.) On the sea represented by a cartesian plane, each ship is located at an integer point, and each integer poin
阅读全文
摘要:A quack is a data structure combining properties of both stacks and queues. It can be viewed as a list of elements written left to right such that thr
阅读全文
摘要:A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down). Write a function to count the total strobog
阅读全文
摘要:A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down). Find all strobogrammatic numbers that are o
阅读全文
摘要:Dynamic programming solution State: dp[i]: the minimum cost to cover all positions from[0, i]. (left shift by 1 to get 0 index) // if position i is al
阅读全文