![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Cracking the coding interview
文章平均质量分 75
java_wliang
这个作者很懒,什么都没留下…
展开
-
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 · 520 阅读 · 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 · 447 阅读 · 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 · 406 阅读 · 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 · 521 阅读 · 0 评论 -
动态规划——最长公共子序列问题
求最长公共子序列长度 以及对应子序列若给定序列 ABCDEFG , 则 ABC , CDE, ABCDEFG 等都是其自序列原创 2014-10-21 20:57:55 · 435 阅读 · 0 评论 -
Cracking the coding interview--Q1.8
原文:Assume you have a method isSubstring which checks if one word is a substring of another. Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 using only one call to isSub原创 2014-10-21 10:15:11 · 538 阅读 · 0 评论 -
Cracking the coding interview--Q1.5
原文:Write a method to replace all spaces in a string with ‘%20’.译文:写一个函数,把字符串中所有的空格替换为%20 。package chapter_1_arraysandstring;import java.util.Scanner;/** * 写一个函数,把字符串中所有的空格替换原创 2014-10-20 16:09:11 · 378 阅读 · 0 评论 -
Cracking the coding interview--Q1.6
原文:Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees. Can you do this in place?译文:一张图像表示成NxN的矩阵,图像中每个像原创 2014-10-20 19:34:10 · 395 阅读 · 0 评论 -
Cracking the coding interview--Q1.4
原文:Write a method to decide if two strings are anagrams or not.译文:写一个函数判断两个字符串是否是变位词。变位词(anagrams)指的是组成两个单词的字符相同,但位置不同的单词。比如说, abbcd和abcdb就是一对变位词。原创 2014-10-20 15:13:54 · 389 阅读 · 0 评论 -
Cracking the coding interview--Q1.7
原文:Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0.译文:写一个函数处理一个MxN的矩阵,如果矩阵中某个元素为0,那么把它所在的行和列都置为0.遍历一次矩阵,当遇到元素等于0时,记录下这个元素对应的行和列。原创 2014-10-20 21:25:39 · 416 阅读 · 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 · 390 阅读 · 0 评论 -
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 · 464 阅读 · 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 · 323 阅读 · 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 · 446 阅读 · 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 · 334 阅读 · 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 · 507 阅读 · 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 · 439 阅读 · 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 · 403 阅读 · 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 · 486 阅读 · 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 · 448 阅读 · 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 · 448 阅读 · 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 · 494 阅读 · 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 · 485 阅读 · 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 · 421 阅读 · 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 · 485 阅读 · 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 · 476 阅读 · 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 · 348 阅读 · 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 · 396 阅读 · 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 · 328 阅读 · 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 · 367 阅读 · 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 · 472 阅读 · 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 · 513 阅读 · 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 · 432 阅读 · 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 · 486 阅读 · 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 · 347 阅读 · 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 · 430 阅读 · 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 · 418 阅读 · 0 评论 -
Cracking the coding interview--Q1.2
题目原文:Write code to reverse a C-Style String. (C-String means that “abcd” is represented as five characters, including the null character.)译文:写代码翻转一个C风格的字符串。(C风格的意思是"abcd"需要用5个字符来表示,包原创 2014-10-19 21:02:05 · 370 阅读 · 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 · 431 阅读 · 0 评论 -
Cracking the coding interview--Q1.3
原文:Design an algorithm and write code to remove the duplicate characters in a string without using any additional buffer. NOTE: One or two additional variables are fine. An extra copy of the array原创 2014-10-20 10:42:39 · 400 阅读 · 0 评论