
CareerCup 150
文章平均质量分 59
H_Arbiter
这个作者很懒,什么都没留下…
展开
-
CareerCup 1.6
1.6 Given an image represented by an N*N 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?void rotate(vector >& matrix,原创 2013-03-29 11:31:43 · 822 阅读 · 0 评论 -
CareerCup 3.1
3.1 Describe how you could use a single array to implement three stacks.Approach 1: Fixed Divisionclass ThreeStack {private: int stackSize; int *buffer; int stackPointer[3];public:原创 2013-06-25 02:43:46 · 848 阅读 · 0 评论 -
CareerCup 2.7
2.7 Implement a function to check if a linked list is a palindrome.struct ListNode { int data; ListNode *next; ListNode(int x) : data(x), next(NULL) {}};Solution #1: Iterative App原创 2013-06-24 15:14:02 · 510 阅读 · 0 评论 -
CareerCup 3.2
3.2 How would you design a stack which, in addition to push and pop, also has a functionminwhich returns the minimum element?Push,pop and min should all operate in O(1) time.Solution 1:t原创 2013-06-25 08:01:48 · 416 阅读 · 0 评论 -
CareerCup 3.3
3.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 same threshold. Impleme原创 2013-06-26 00:06:52 · 481 阅读 · 0 评论 -
CareerCup 3.4
3.4 In the classic problem of the Towers of Hanoi, you have 3 towers and N disks of different sizes which can slide onto any tower. The puzzle starts with disks sorted in ascending order of size from原创 2013-06-26 07:04:00 · 536 阅读 · 0 评论 -
CareerCup 3.5
3.5 Implement a MyQueue class which implements a queue using two stacks.template class MyQueue {private: stack oldest, newest; void shiftStacks() { if (oldest.empty()) {原创 2013-06-26 07:47:12 · 487 阅读 · 0 评论 -
CareerCup 3.6
3.6 Write a program to sort a stack in ascending order (with biggest items on top). You may use additional stacks to hold items, but you may not copy the elements into any other data structure (such a原创 2013-06-26 08:02:32 · 478 阅读 · 0 评论 -
CareerCup 3.7
3.7 An animal shelter holds only dogs and cats, and operates on a strictly "first in, first out" basis. People must adopt either the "oldest" (based on arrival time) of all animals at the shelter, or原创 2013-06-27 07:58:41 · 546 阅读 · 0 评论 -
CareerCup 4.1
4.1 Implement a function to check if a binary tree is balanced. For the purpose of this question, a balanced tree is defined to be a tree such that the height of the two subtrees of any node never dif原创 2013-06-28 07:20:43 · 405 阅读 · 0 评论 -
CareerCup 4.4
4.4 Given a binary search tree, design an algorithm which creates a linked list of all the nodes at each depth (e.g., if you have a tree with depth D, you'll have D linked lists).原创 2013-07-02 14:02:13 · 593 阅读 · 0 评论 -
CareerCup 4.3
4.3 Given a sorted (increasing order) array, write an algorithm to create a binary search tree with minimal height.struct TreeNode { int val; TreeNode *left, *right; TreeNode(int v) : va原创 2013-07-02 13:39:18 · 434 阅读 · 0 评论 -
CareerCup 4.6
4.6 Write an algorithm to find the 'next' node (i.e., in-order successor) of a given node in a binary search tree. You may assume that each node has a link to its parent.struct TreeNode { int va原创 2013-07-03 05:48:22 · 608 阅读 · 0 评论 -
CareerCup 4.5
4.5 Implement a function to check if a binary tree is a binary search tree.struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NUL原创 2013-07-03 03:14:07 · 506 阅读 · 0 评论 -
CareerCup 2.6
2.6 Given a circular linked list, implement an algorithem which returns the node at the beginning of the loop.struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(原创 2013-06-24 13:49:16 · 442 阅读 · 0 评论 -
CareerCup 4.8
4.8 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.A tree T2 is a subtree of T1 if there exi原创 2013-07-08 09:37:34 · 533 阅读 · 0 评论 -
CareerCup 1.7
1.7 Write an algorithm such that if an element in an M*N matrix is 0, its entire row and column are set to 0.void setZeros(vector >& matrix) { int m = matrix.size(); int n = matrix[0].size()原创 2013-03-29 12:05:02 · 473 阅读 · 0 评论 -
CareerCup 1.8
1.8 Assume you have a method isSubstringwhich checks if one word is a substring of another. Given two strings, s1 and s2, write code to check ifs2 is a rotation of s1 using only one call to is原创 2013-03-29 12:31:35 · 871 阅读 · 0 评论 -
CareerCup 2.3
2.3 Implement an algorithm to delete a node in the middle of a singly linked list, given only access to that node.struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), nex原创 2013-03-31 09:43:24 · 330 阅读 · 0 评论 -
CareerCup 2.2
2.2 Implement an algorithm to find the kth to last element of a singly linked list.struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {}};ListNode* nthT原创 2013-03-31 08:22:17 · 409 阅读 · 0 评论 -
CareerCup 2.1
2.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?struct ListNode { int val; ListNode *next;原创 2013-03-30 08:08:18 · 498 阅读 · 0 评论 -
CareerCup 2.4
2.4 Write code to partition a linked list around a value x, such that all nodes less than x come before all nodes greater than or equal to x.struct ListNode { int val; ListNode *next;原创 2013-04-01 01:11:21 · 554 阅读 · 0 评论 -
CareerCup 1.4
1.4 Write a method to replace all spaces in a string with '%20'. You may assume that the string has sufficient space at the end of the string to hold the additional characters, and that you are given原创 2013-03-21 13:50:43 · 671 阅读 · 0 评论 -
CareerCup 1.1
1.1 Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structure?bool isUniqueChar(string s) { vector c(256, false); for (int原创 2013-03-14 12:18:21 · 536 阅读 · 0 评论 -
CareerCup 1.2
1.2 Implement a function void reverse(char* str) in C or C++ which reverses a null-terminated string.void reverse(char* str) { char *p, *q, tmp; p = q = str; if (str) { while (原创 2013-03-21 12:37:33 · 597 阅读 · 0 评论 -
CareerCup 1.3
1.3 Given two strings, write a method to decide if one is a permutation of the other.Solution 1:bool isPermutation(string a, string b) { if (a.length() != b.length()) return false;原创 2013-03-21 13:28:02 · 533 阅读 · 0 评论 -
CareerCup 1.5
1.5 Implement a method to perform basic string compression using the counts of repeated characters. For example, the string aabcccccaa would become a2b1c5a3. If the "compressed" string would not becom原创 2013-03-22 11:50:55 · 550 阅读 · 0 评论 -
CareerCup 2.5
2.5 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 func原创 2013-04-01 11:08:30 · 422 阅读 · 0 评论 -
CareerCup 4.7
4.7 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 searc原创 2013-07-03 08:29:33 · 549 阅读 · 0 评论 -
CareerCup 4.2
4.2 Given a directed graph, design an algorithm to find out whether there is a route between two nodes.#include #include #include using namespace std;struct GraphNode { enum State {unvisite原创 2013-07-02 13:18:08 · 495 阅读 · 0 评论