工作面试
zldeng_scir
菜鸟!
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
经典面试题收集
1、最大间隙问题给定n个实数,求着n个实数在实轴上向量2个数之间的最大差值,要求线性的时间算法。方案1:最先想到的方法就是先对这n个数据进行排序,然后一遍扫描即可确定相邻的最大间隙。但该方法不能满足线性时间的要求。故采取如下方法:找到n个数据中最大和最小数据max和min。用n-2个点等分区间[min, max],即将[min, max]等分为n-1个区间(前闭后开区间),将这原创 2012-06-07 14:41:06 · 776 阅读 · 0 评论 -
No. 14 - Last Number in a Circle
No. 14 - Last Number in a CircleProblem: If we delete the mth number from a circle which is composed of numbers 0, 1, …, n-1 counting from 0 at every time, what is the last number?For exam转载 2012-07-13 19:44:40 · 686 阅读 · 0 评论 -
No. 06 - Post-order Traversal Sequences of Binary Search Trees
No. 06 - Post-order Traversal Sequences of Binary Search TreesProblem: Determine whether an input array is a post-order traversal sequence of a binary tree or not. If it is, return true; otherwi转载 2012-07-13 19:40:40 · 756 阅读 · 0 评论 -
No. 04 - Paths with Specified Sum in Binary Tree
No. 04 - Paths with Specified Sum in Binary TreeQuestion: All nodes along children pointers from root to leaf nodes form a path in a binary tree. Given a binary tree and a number, please print o转载 2012-07-13 19:39:40 · 808 阅读 · 0 评论 -
No. 01 - Binary Search Tree and Double-linked List
No. 01 - Binary Search Tree and Double-linked ListQuestion: Convert a binary search tree to a sorted double-linked list. We can only change the target of pointers, but cannot create any new node转载 2012-07-13 19:36:18 · 809 阅读 · 0 评论 -
No. 10 - K-th Node from End
No. 10 - K-th Node from EndProblem: Get the Kth node from end of a linked list. It counts from 1 here, so the 1st node from end is the tail of list. For instance, given a linked list with转载 2012-07-13 19:42:49 · 1352 阅读 · 0 评论 -
No. 11 - Print Binary Trees from Top to Bottom
No. 11 - Print Binary Trees from Top to BottomProblem: Please print a binary tree from its top level to bottom level, and print nodes from left to right if they are in same level. For exam转载 2012-07-13 19:43:12 · 816 阅读 · 0 评论 -
No. 12 - Mirror of Binary Trees
No. 12 - Mirror of Binary TreesProblem: Please implement a function which returns mirror of a binary tree.Binary tree nodes are defined as:struct BinaryTreeNode{ int转载 2012-07-13 19:43:44 · 774 阅读 · 0 评论 -
No. 08 - Calculate 1+2+…+n
No. 08 - Calculate 1+2+…+nProblem: Calculate 1+2+…+n without multiplication, division, key words for, while, if, else,switch, case, as well as conditional operator (A ? B : C).Analysis: Th转载 2012-07-13 19:41:46 · 1587 阅读 · 0 评论 -
No. 17 - Queue Implemented with Two Stacks
No. 17 - Queue Implemented with Two StacksProblem: Implement a queue with two stacks. The class for queues is declared in C++ as below. Please implement two functions: appendTail to append an el转载 2012-07-13 19:46:25 · 759 阅读 · 0 评论 -
No. 18 - Reverse a Linked List
No. 18 - Reverse a Linked ListProblem: Implement a function to reverse a linked list, and return the head of the reversed list. A list node is defined as below:struct ListNode{ int转载 2012-07-13 19:46:55 · 1222 阅读 · 0 评论 -
No. 25 - Edit Distance
No. 25 - Edit DistanceProblem: Implement a function which gets the edit distance of two input strings. There are three types of edit operations: insertion, deletion and substitution. Edit distan转载 2012-07-14 15:13:52 · 1912 阅读 · 0 评论 -
散列表中冲突的处理方法(开放寻址法)
在是使用散列表时,最重要的两个步骤就是设计散列函数和冲突处理方式。 其中冲突的处理方式主要有:线性探查:线性探查在散列的时候,如果当前计算出的位置已经被存储,那么就顺序的向后查找,知道找到空位置或则是所有位置均不为空失败。线性探查的散列函数形式为:h(k,i)=(h'(k,i) + i) mod m,i = 0,1,2....m-1二次探查二次探查原创 2012-08-22 10:45:21 · 3751 阅读 · 0 评论 -
No. 15 - Fibonacci Sequences
No. 15 - Fibonacci SequencesProblem: Please implement a function which returns the nth number in Fibonacci sequences with an input n. Fibonacci sequence is defined as:Analysis: It is转载 2012-07-13 19:45:19 · 972 阅读 · 0 评论 -
No. 30 - Median in Stream
No. 30 - Median in StreamQuestion: How to get the median from a stream of numbers at any time? The median is middle value of numbers. If the count of numbers is even, the median is defined as th转载 2012-07-14 15:16:22 · 885 阅读 · 0 评论 -
No. 31 - Binary Search Tree Verification
No. 31 - Binary Search Tree VerificationQuestion: How to verify whether a binary tree is a binary search tree?For example, the tree in Figure 1 is a binary search tree.A node in bi转载 2012-07-14 15:17:08 · 728 阅读 · 0 评论 -
No. 02 - Stack with Function min()
No. 02 - Stack with Function min()Problem: Define a stack, in which we can get its minimum number with a function min. In this stack, the time complexity of min(), push() and pop() are all O(1).转载 2012-07-13 19:38:24 · 659 阅读 · 0 评论 -
No. 29 - Loop in List
No. 29 - Loop in ListQuestion 1: How to check whether there is a loop in a linked list? For example, the list in Figure 1 has a loop.A node in list is defined as the following structure:转载 2012-07-14 15:15:54 · 844 阅读 · 0 评论 -
No. 27 - Area of Rectangles
No. 27 - Area of RectanglesProblem: Please implement a function which gets area of a set of rectangles, whose edges are parallel to X-axis or Y-axis.Rectangles are defined as the following:转载 2012-07-14 15:14:51 · 2120 阅读 · 0 评论 -
求逆序数算法
求逆序数的算法,其实就是归并排序的原理。只需要在排序的过程中记录一下交换得次数。 这种算法其实是一种动态规划的算法。运用了分治策略,将大问题化作一个个小问题。例如将数组a[]分成b[],c[],左右两个部分。逆序数的个数就是左 数组中逆序数的个数和右数组逆序数的个数,然后将两个数组合并的时候,注意一下左边的数组有多少个数比右边的数组的多少数值要大。 #include #i转载 2012-07-16 08:41:25 · 3279 阅读 · 0 评论 -
No. 28 - A Pair with the Maximal Difference
No. 28 - A Pair with the Maximal DifferenceProblem: A pair contains two numbers, and its second number is on the right side of the first one in an array. The difference of a pair is the minus re转载 2012-07-14 15:15:19 · 716 阅读 · 0 评论 -
No. 13 - First Character Appearing Only Once
No. 13 - First Character Appearing Only OnceProblem: Implement a function to find the first character in a string which only appears once.For example: It returns ‘b’ when the input is “abaccde转载 2012-07-13 19:44:09 · 744 阅读 · 0 评论 -
No. 07 - Reverse words in a sentence
No. 07 - Reverse words in a sentenceProblem: Reverse the order of words in a sentence, but keep words themselves unchanged. Words in a sentence are divided by blanks. For instance, the reversed转载 2012-07-13 19:41:10 · 1062 阅读 · 0 评论 -
No. 03 - Maximum Sum of All Sub-arrays
No. 03 - Maximum Sum of All Sub-arraysQuestion: A sub-array has one number of some continuous numbers. Given an integer array with positive numbers and negative numbers, get the maximum sum of a转载 2012-07-13 19:39:07 · 806 阅读 · 0 评论 -
No. 20 - Number of 1 in a Binary
No. 20 - Number of 1 in a BinaryProblem: Please implement a function to get the number of 1s in an integer. For example, the integer 9 is 1001 in binary, so it returns 2 since there are two bits转载 2012-07-13 19:47:52 · 1350 阅读 · 0 评论 -
No. 09 - Numbers with a Given Sum
No. 09 - Numbers with a Given SumProblem 1: Given an increasingly sorted array and a number s, please find two numbers whose sum is s. If there are multiple pairs with sum s, just output any one转载 2012-07-13 19:42:23 · 676 阅读 · 0 评论 -
No. 05 - The Least k Numbers
No. 05 - The Least k NumbersQuestion: Please find out the least k numbers out of n numbers. For example, if given the 8 numbers 4, 5, 1, 6, 2, 7, 3 and 8, please return the least 4 numbers 1, 2,转载 2012-07-13 19:40:12 · 1204 阅读 · 0 评论 -
二叉树的遍历
二叉树节点的定义: struct treeT{ ElemType key; struct treeT* left; struct treeT* right;}*pTreeT递归实现:先序遍历:void BT_PreOrder(pTreeT root){ if (NULL != root) { visit(root);原创 2012-07-12 10:46:37 · 651 阅读 · 0 评论 -
笔试题总结
1、求二叉树中节点的最大距离...如果我们把二叉树看成一个图,父子节点之间的连线看成是双向的,我们姑且定义"距离"为两节点之间边的个数。求一棵二叉树中相距最远的两个节点之间的距离。This is interesting... Also recursively, the longest distance between two nodes must be either from ro转载 2012-07-09 15:07:54 · 706 阅读 · 0 评论 -
No. 16 - Maximal Length of Incremental Subsequences
No. 16 - Maximal Length of Incremental SubsequencesProblem: Given an unsorted array, find the max length of subsequence in which the numbers are in incremental order.For example: If the in转载 2012-07-13 19:45:53 · 689 阅读 · 0 评论 -
No. 19 - Left Rotation of String
No. 19 - Left Rotation of StringProblem: Left rotation of a string is to move some leading characters to its tail. Please implement a function to rotate a string. For example, if the input转载 2012-07-13 19:47:24 · 1925 阅读 · 0 评论 -
No. 26 - Minimal Number of Coins for Change
No. 26 - Minimal Number of Coins for ChangeProblem: Please implement a function which gets the minimal number of coins, whose value is v1, v2, …, vn, to make change for an amount of money with v转载 2012-07-14 15:14:21 · 1728 阅读 · 0 评论 -
No. 24 - Intersection of Sorted Arrays
No. 24 - Intersection of Sorted Arrays Problem: Please implement a function which getsthe intersection of two sorted arrays. Assuming numbers in each array areunique. For example, ifthe two转载 2012-07-14 15:11:38 · 864 阅读 · 0 评论 -
No. 21 - Push and Pop Sequences ofStacks
No. 21 - Push and Pop Sequences ofStacks Problem: Given two integer sequences, one ofwhich is the push sequence of a stack, please check whether the other sequenceis a corresponding pop sequence转载 2012-07-14 15:10:22 · 1149 阅读 · 0 评论 -
No. 33 - Maximums in Sliding Windows
No. 33 - Maximums in Sliding WindowsQuestion: Given an array of numbers and a sliding window size, how to get the maximal numbers in all sliding windows?For example, if the input array is转载 2012-07-14 15:18:13 · 689 阅读 · 0 评论 -
No. 32 - Remove Numbers in Array
No. 32 - Remove Numbers in ArrayQuestion: Given an array and a value, how to implement a function to remove all instances of that value in place and return the new length? The order of elements转载 2012-07-14 15:17:43 · 616 阅读 · 0 评论 -
No. 22 - Turning Number in an Array
No. 22 - Turning Number in an Array Problem: Turning number is the maximum number in an array whichincreases and then decreases. This kind of array is also named unimodal array.Please write a fu转载 2012-07-14 15:10:44 · 727 阅读 · 0 评论 -
No. 34 - String Path in Matrix
No. 34 - String Path in MatrixQuestion: How to implement a function to check whether there is a path for a string in a matrix of characters? It moves to left, right, up and down in a matrix, an转载 2012-07-14 15:18:42 · 878 阅读 · 0 评论 -
No. 23 - Palindrome Numbers
No. 23 - Palindrome Numbers Problem: Please implement a function which checks whether a numberis a palindrome or not. For example, 121 is a palindrome, while 123 is not. Analysis: Many candi转载 2012-07-14 15:11:08 · 1559 阅读 · 0 评论 -
用归并排序对链表进行排序
当我们需要对链表进行排序时,由于不能对它的元素进行随机访问,所以更适合使用归并排序,大名鼎鼎的快速排序用到链表上,效率也很低,原因还是在于不能对链表中的元素进行随机访问,同理,采用堆排序更是不可能的事情。 算法具体实现时需要一个指向头节点(链表的第一个节点,链表中不包含额外的一个节点来作头节点)的指针,这是因为在算法实现的时候,不大可能第一个节点正好就是所有元素中最小的一个,则转载 2012-09-23 19:59:53 · 1110 阅读 · 0 评论
分享