随笔分类 - Algorithm
classic algorithm, problem
摘要:赠券收集者问题(coupon collector's problem),就是买东西的时候会又不同的卡片赠送,求集齐这些卡片需要购买的产品的数量的期望值。
见wiki [coupon collector's problem https://en.wikipedia.org/wiki/Coupon_co...
阅读全文
摘要:Given an directed graph, a topological order of the graph nodes is defined as follow:
For each directed edge A B in graph, A must before B in the ord...
阅读全文
摘要:Given a root of Binary Search Tree with unique value for each node. Remove the node with given value. If there is no such a node with given value in ...
阅读全文
摘要:Design an algorithm and write code to serialize and deserialize a binary tree. Writing the tree to a file is called 'serialization' and reading back ...
阅读全文
摘要:Given two values k1 and k2 (where k1 < k2) and a root pointer to a Binary Search Tree. Find all the keys of tree in range k1 to k2. i.e. print all x ...
阅读全文
摘要:Given an array of integers, the majority number is the number that occurs more than 1/3 of the size of the array.
Find it.
Have you met this question...
阅读全文
摘要:Given 2 n + 2 numbers, every numbers occurs twice except two, find them.
Have you met this question in a real interview? Yes
Example
Given [1,2,2,3,4...
阅读全文
摘要:Given string A representative a positive integer which has N digits, remove any k digits of the number, the remaining digits are arranged according t...
阅读全文
摘要:Given a (decimal e.g. 3.72) number that is passed in as a string, return the binary representation that is passed in as a string. If the fractional p...
阅读全文
摘要:Calculate the an % b where a, b and n are all 32bit integers.
Have you met this question in a real interview? Yes
Example
For 231 % 3 = 2
For 1001000...
阅读全文
摘要:Given two 32 bit numbers, N and M, and two bit positions, i and j. Write a method to set all bits between i and j in N equal to M (e g , M becomes a ...
阅读全文
摘要:Determine the number of bits required to flip if you want to convert integer n to integer m.
Have you met this question in a real interview? Yes
Exam...
阅读全文
摘要:Given n pieces of wood with length L[i] (integer array). Cut them into small pieces to guarantee you could have equal or more than k pieces with the ...
阅读全文
摘要:Implement int sqrt(int x).
Compute and return the square root of x.
Have you met this question in a real interview? Yes
Example
sqrt(3) = 1
sqrt(4) =...
阅读全文
摘要:For a given sorted array (ascending order) and a target number, find the first index of this number in O(log n) time complexity.
If the target number...
阅读全文
摘要:Given an integer array, find a subarray with sum closest to zero. Return the indexes of the first number and last number.
Have you met this question ...
阅读全文
摘要:Given an array nums of integers and an int k, partition the array (i.e move the elements in "nums") such that:All elements < k are moved to the leftA...
阅读全文
摘要:Given an integer array, find a subarray where the sum of numbers is zero. Your code should return the index of the first number and the index of the ...
阅读全文
摘要:Given two strings, find the longest common substring.
Return the length of it.
Have you met this question in a real interview? Yes
Example
Given A = ...
阅读全文
摘要:Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.
For example, given n = 12...
阅读全文

浙公网安备 33010602011771号