
Cracking the coding interview
文章平均质量分 75
java_wliang
这个作者很懒,什么都没留下…
展开
-
Cracking the coding interview--Q8.8
原文:Write an algorithm to print all ways of arranging eight queens on a chess board so that none of them share the same row, column or diagonal.译文:经典的八皇后问题,即在一个8*8的棋盘上放8个皇后,使得这8个皇后无法互相攻击( 任原创 2014-12-15 21:08:01 · 501 阅读 · 0 评论 -
Cracking the coding interview--Q8.7
原文:Given an infinite number of quarters (25 cents), dimes (10 cents), nickels (5 cents) and pennies (1 cent), write code to calculate the number of ways of representing n cents.译文:我们有25分,1原创 2014-12-15 20:45:32 · 565 阅读 · 0 评论 -
Cracking the coding interview--Q9.7
原文:A circus is designing a tower routine consisting of people standing atop one another’s shoulders. For practical and aesthetic reasons, each person must be both shorter and lighter than the pers原创 2014-12-15 20:19:07 · 517 阅读 · 0 评论 -
Cracking the coding interview--Q9.6
原文:Given a matrix in which each row and each column is sorted, write a method to find an element in it.译文:给出一个矩阵,其中每一行和每一列都是有序的,写一个函数在矩阵中找出指定的数。矩阵是有序的,因此要利用这一点,当矩阵中元素和要查找的元素对比后,原创 2014-12-15 12:50:12 · 538 阅读 · 0 评论 -
Cracking the coding interview--Q9.5
原文:Given a sorted array of strings which is interspersed with empty strings, write a method to find the location of a given string.Example: find “ball” in [“at”, “”, “”, “”, “ball”, “”, “”, “c原创 2014-12-15 12:29:56 · 462 阅读 · 0 评论 -
Cracking the coding interview--Q9.4
原文:If you have a 2 GB file with one string per line, which sorting algorithm would you use to sort the file and why?译文:如果你有个2GB的文件,其中每一行是一个字符串,你会使用哪种算法来排序,为什么?当面试官说到2GB文件的时候,转载 2014-12-15 11:20:07 · 433 阅读 · 0 评论 -
Cracking the coding interview--Q9.3
原文:Given a sorted array of n integers that has been rotated an unknown number of times, give an O(log n) algorithm that finds an element in the array. You may assume that the array was originally原创 2014-12-15 11:07:55 · 506 阅读 · 0 评论 -
Cracking the coding interview--Q9.2
原文:Write a method to sort an array of strings so that all the anagrams are next to each other.译文:写一个函数对字符串数组排序,使得所有的变位词都相邻。解答首先需要理解什么是变位词?变位词就是字符组成的元素相同,只不过位置不同而已,例如:abc与原创 2014-12-15 09:55:40 · 475 阅读 · 0 评论 -
Cracking the coding interview--Q9.1
原文:You are given two sorted arrays, A and B, and A has a large enough buffer at the end to hold B. Write a method to merge B into A in sorted order.译文:A和B是两个有序数组(假设为递增序列),而且A的长度足以放下A和B中所有的原创 2014-12-14 21:35:37 · 358 阅读 · 0 评论 -
Cracking the coding interview--Q8.5
原文:Implement an algorithm to print all valid (e.g., properly opened and closed) combinations of n-pairs of parentheses.EXAMPLE:input: 3 (e.g., 3 pairs of parentheses)output: ((())), ((原创 2014-12-10 19:28:43 · 467 阅读 · 0 评论 -
Cracking the coding interview--Q8.4
原文:Write a method to compute all permutations of a string译文:写一个函数返回一个串的所有排列比如,计算 “abc”的全排列abc acb bac bca cab cba对于一个长度为n的串,它的全排列共有A(n, n)=n!种。这个问题也是一个递归的问题, 不过可以用不原创 2014-12-10 18:49:19 · 519 阅读 · 0 评论 -
Cracking the coding interview--Q8.3
原文:Write a method that returns all subsets of a set.译文:写一个函数返回一个集合中的所有子集。对于一个集合,它的子集一共有2n 个(包括空集和它本身)。它的任何一个子集, 我们都可以理解为这个集合本身的每个元素是否出现而形成的一个序列。比如说, 对于集合{1, 2, 3},空集表示一个元素都没出现,原创 2014-12-10 17:37:23 · 470 阅读 · 0 评论 -
Cracking the coding interview--Q8.2
原文:Imagine a robot sitting on the upper left hand corner of an NxN grid. The robot can only move in two directions: right and down. How many possible paths are there for the robot?FOLLOW UP原创 2014-11-26 14:23:31 · 502 阅读 · 0 评论 -
Cracking the coding interview--Q8.1
原文:Write a method to generate the nth Fibonacci number.译文:写一个函数来产生第n个斐波那契数。斐波那契数列的定义如下:f(1) = f(2) = 1;f(n) = f(n-1) + f(n-2);package chapter_8_Recursion;import ja原创 2014-11-26 10:57:58 · 413 阅读 · 0 评论 -
Cracking the coding interview--Q5.7
原文:An array A[1…n] contains all the integers from 0 to n except for one number which is missing. In this problem, we cannot access an entire integer in A with a single operation. The elements of A原创 2014-11-26 10:18:51 · 450 阅读 · 0 评论 -
Cracking the coding interview--Q5.6
原文:Write a program to swap odd and even bits in an integer with as few instructions as possible (e.g., bit 0 and bit 1 are swapped, bit 2 and bit 3 are swapped, etc).译文:写程序交换一个整数二进制表示中的奇数位原创 2014-11-24 20:12:33 · 351 阅读 · 0 评论 -
Cracking the coding interview--Q5.5
原文:Write a function to determine the number of bits required to convert integer A to integer B.Input: 31, 14Output: 2译文:写程序计算从整数A变为整数B需要修改的二进制位数。输入:31,14输出:2原创 2014-11-24 19:20:06 · 429 阅读 · 0 评论 -
Cracking the coding interview--Q5.3
原文:Given an integer, print the next smallest and next largest number that have the same number of 1 bits in their binary representation.译文:给定一个整数x,找出另外两个整数,这两个整数的二进制表示中1的个数和x相同, 其中一个是比x大的数原创 2014-11-24 15:59:19 · 554 阅读 · 0 评论 -
Cracking the coding interview--Q4.8
原文:You are given a binary tree in which each node contains a value. Design an algorithm to print all paths which sum up to that value. Note that it can be any path in the tree - it does not have t原创 2014-11-18 14:35:17 · 520 阅读 · 0 评论 -
Cracking the coding interview--Q4.7
原文:You have two very large binary trees: T1, with millions of nodes, and T2, with hundreds of nodes. Create an algorithm to decide if T2 is a subtree of T1译文:有两棵很大的二叉树:T1有上百万个结点,T2有上百个结点。写原创 2014-11-17 21:16:34 · 433 阅读 · 0 评论 -
Cracking the coding interview--Q4.6
原文:Design an algorithm and write code to find the first common ancestor of two nodes in a binary tree. Avoid storing additional nodes in a data structure. NOTE: This is not necessarily a binary se原创 2014-11-17 20:26:00 · 406 阅读 · 0 评论 -
Cracking the coding interview--Q4.5
原文:Write an algorithm to find the ‘next’ node (i.e., in-order successor) of a given node in a binary search tree where each node has a link to its parent.译文:给定二叉查找树的一个结点, 写一个算法查找它的“下一个”结点(原创 2014-11-17 16:06:21 · 391 阅读 · 0 评论 -
Cracking the coding interview--Q4.4
原文:Given a binary search tree, design an algorithm which creates a linked list of all the nodes at each depth (i.e., if you have a tree with depth D, you’ll have D linked lists).译文:给定一棵二叉查原创 2014-11-15 21:43:35 · 507 阅读 · 0 评论 -
Cracking the coding interview--Q4.3
原文:Given a sorted (increasing order) array, write an algorithm to create a binary tree with minimal height.译文:给定一个有序数组(递增),写程序构建一棵具有最小高度的二叉树。想要使构建出来的二叉树高度最小,那么对于任意结点, 它的左子树和右子树的结原创 2014-11-15 21:14:12 · 454 阅读 · 0 评论 -
Cracking the coding interview--Q4.2
原文:Given a directed graph, design an algorithm to find out whether there is a route between two nodes.译文:给定一个有向图,设计算法判断两结点间是否存在路径。根据题意,给定一个有向图和起点终点,判断从起点开始,是否存在一条路径可以到达终点。 考查的就是图原创 2014-11-15 13:27:42 · 353 阅读 · 0 评论 -
Cracking the coding interview--Q4.1
原文:Implement a function to check if a tree is balanced. For the purposes of this question, a balanced tree is defined to be a tree such that no two leaf nodes differ in distance from the root by m原创 2014-11-14 15:55:40 · 495 阅读 · 0 评论 -
Cracking the coding interview--Q5.2
原文:Given a (decimal - e.g. 3.72) number that is passed in as a string, print the binary representation.If the number can not be represented accurately in binary, print “ERROR”.译文:给定一个字符串类型转载 2014-11-13 13:50:10 · 539 阅读 · 0 评论 -
Cracking the coding interview--Q5.1
原文:You are 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 substring of N located at i and star原创 2014-11-13 12:00:55 · 452 阅读 · 0 评论 -
Cracking the coding interview--Q3.6
原文:Write a program to sort a stack in ascending order. You should not make any assumptions about how the stack is implemented. The following are the only functions that should be used to write thi原创 2014-11-12 16:28:00 · 516 阅读 · 0 评论 -
Cracking the coding interview--Q3.5
原文:Implement a MyQueue class which implements a queue using two stacks.译文:使用两个栈实现一个队列MyQueue。队列是先进先出的数据结构(FIFO),栈是先进后出的数据结构(FILO), 用两个栈来实现队列的最简单方式是:进入队列则往第一个栈压栈, 出队列则将第一个栈的数据依次压入原创 2014-11-12 14:30:17 · 484 阅读 · 0 评论 -
Cracking the coding interview--Q3.4
原文:In the classic problem of the Towers of Hanoi, you have 3 rods and N disks of different sizes which can slide onto any tower. The puzzle starts with disks sorted in ascending order of size from原创 2014-11-12 13:37:48 · 369 阅读 · 0 评论 -
Cracking the coding interview--Q3.3
原文:Imagine a (literal) stack of plates. If the stack gets too high, it might topple. Therefore, in real life, we would likely start a new stack when the previous stack exceeds some threshold. Impl原创 2014-11-06 20:16:21 · 471 阅读 · 0 评论 -
Cracking the coding interview--Q3.2
原文:How would you design a stack which, in addition to push and pop, also has a function min which returns the minimum element? Push, pop and min should all operate in O(1) time.译文:实现一个栈,除了原创 2014-10-31 16:04:49 · 451 阅读 · 0 评论 -
Cracking the coding interview--Q3.1
原文:Describe how you could use a single array to implement three stacks.译文:你如何只用一个数组实现三个栈?原创 2014-10-31 11:44:24 · 418 阅读 · 0 评论 -
Cracking the coding interview--Q2.5
原文:Given a circular linked list, implement an algorithm which returns node at the beginning of the loop.DEFINITIONCircular linked list: A (corrupt) linked list in which a node’s next point原创 2014-10-30 21:52:00 · 421 阅读 · 0 评论 -
Cracking the coding interview--Q2.4
原文:You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1’s digit is at the head of the list. Write a f原创 2014-10-30 16:16:12 · 377 阅读 · 0 评论 -
Cracking the coding interview--Q2.3
原文:Implement an algorithm to delete a node in the middle of a single linked list, given only access to that node.EXAMPLEInput: the node ‘c’ from the linked list a->b->c->d->e Result: nothi原创 2014-10-30 14:13:55 · 426 阅读 · 0 评论 -
Cracking the coding interview--Q2.2
原文:Implement an algorithm to find the nth to last element of a singly linked list.译文:实现一个算法从一个单链表中返回倒数第n个元素。原创 2014-10-30 11:10:23 · 443 阅读 · 0 评论 -
Cracking the coding interview--Q2.1
原文:Write code to remove duplicates from an unsorted linked list.FOLLOW UPHow would you solve this problem if a temporary buffer is not allowed?译文:从一个未排序的链表中移除重复的项进一步地,如果不允许原创 2014-10-28 19:41:21 · 387 阅读 · 0 评论 -
动态规划——最长公共子序列问题
求最长公共子序列长度 以及对应子序列若给定序列 ABCDEFG , 则 ABC , CDE, ABCDEFG 等都是其自序列原创 2014-10-21 20:57:55 · 470 阅读 · 0 评论