摘要:
Given a binary tree, return thezigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7return its zigzag level order traversal as:[ [3], ... 阅读全文
摘要:
Given a sorted array and a number n.How can u find the number of occurance of n in the array . should be o(logn)http://www.careercup.com/question?id=8877058改变一下二分查找的方法,一次找到最左边,另一次找到最右边。#include <iostream>#include <vector>using namespace std;int findPos(vector<int> &a, int left, 阅读全文
摘要:
A circus is designing a tower routine consisting of people standing atop one another’sshoulders. For practical and aesthetic reasons, each person must be both shorter and lighter than the person below him or her. Given the heights and weights of each person in the circus, write a method to compute t 阅读全文
摘要:
Given an array of elements find the largest possible number that canbe formed by using the elements of the array.eg: 10 9ans: 9102 3 5 78ans: 78532100 9ans: 9100http://www.careercup.com/question?id=9334650把字符串排个序,比较方法是循环比较各个字符,如果对应位的字符大于另一个字符串的对应位则返回true,否则false。思想就是类似于要把尽可能大的数位放在更高位。 1 #include < 阅读全文
摘要:
Given an integer 'k' and an sorted array A (can consist of both +ve/-ve nos), output 2 integers from A such that a-b=k.PS:nlogn solution would be to check for the occurence of k-a[i] (using binary search) when you encounter a[i]. methods like hash consume space.Is an O(n) solution with O(1) 阅读全文