由买买提看人间百态

topics

全部话题 - 话题: minvalue
1 (共1页)
l******s
发帖数: 3045
1
来自主题: JobHunting版 - 问一道Uber的电面题
像word ladder ii类似的一开始预处理所有近似点的做法,建一个大的依赖map先。
C#测试了几个,单连通图的,多独立连通图的正面反面用例,都通过了。
//directions = {{"A", "N", "C"}, {"B", "NE", "C"}, {"C", "NE", "D"}, {"A", "
S", "D"}, {"B", "W", "A"}}
// AB
// C
// D
// A <- false
private static bool validDirections(IList> directions)
{
int[,] depend = new int[26, 8]; //8 directions 0:N; 1:NE; 2:E; 3:SE; 4:S
; 5:SW; 6:W; 7:NW
for (int i = 0; i < depend.GetLength(0); i++)
for (int j = 0; j < depend.GetLength(1); j++)
de... 阅读全帖
s**********4
发帖数: 3
2
来自主题: JobHunting版 - 问一个java的函数调用问题
会写c++,只是拿leetcode一个例子来问一下java的函数调用问题:
比如说我现在创建了两个文件:Solution.java和SolutionTest.java:
Solution.java:
public class Solution {
public int maxProfit(int[] prices) {
// Start typing your Java solution below
// DO NOT write main() function
if (prices.length < 2)
return 0;
int maxDiff = 0;
int minValue = prices[0];
for (int i = 1; i < prices.length; ++i) {
if (prices[i] < minValue)
minValue = prices[i];
... 阅读全帖
l********s
发帖数: 358
3
来自主题: JobHunting版 - G电面面经
1. O(n)
从左到右update minValue, 对于A[i]比minValue大,说明A[i]有小的在左边, 记录在
一个boolean array里面
从右到左update maxValue, 对于A[i]比minValue小,说明A[i]有大的在右边
2.
s += compute(i)
在这里call computer(i)两次
1)如果两次值一样,出错的几率是p*p
2)如果两次值不一样,就任意取一个p*p + p*0.5 (可能两个值都错,也有可能一个
对一个错)
3.
同一个machine多线程的话,blockingQueue里面放fileId,sum设为static的
atomicInteger
多个machine的话,就是IPC,一个machine做coordinator,往message queue里面放
fileID。其他machine从message queue里面拿fileID,统计完把结果放到另外一个
message queue里面,coordinator取出结果然后sumAll.
其实就是mapper + reducer
c******a
发帖数: 198
4
来自主题: JobHunting版 - Two CS interview questions
1. Given a method (public int Rand()) that returns any random integer in the
int range, write a wrapper method that returns a random number within a
specific range [min, max], assuming int.MinValue <= min <= max <= int.
MaxValue.
my solution was: min + (Rand() - int.MinValue) * (max - min + 1) / (int.
MaxValue - int.MinValue + 1), and use long type to account for overflow
issue. is this solution correct?
2. Given a M*N matrix where some cells are blocked and there may or may not
be a cell which ... 阅读全帖
f*******h
发帖数: 53
5
来自主题: JobHunting版 - microsoft面经
isBst(Node node, int maxValue, int minValue)
用这个做递归,刚开始maxValue=Integer.MAX_VALUE minValue=Integer.MIN_VALUE
从root做起:
isBst(root.left,root.value,Integer.MIN_VALUE) && isBst(root.right,Integer.
MAX_VALUE, root.value)
明白了么?
i**9
发帖数: 351
6
来自主题: JobHunting版 - 判断 bst 疑问
很多人给出的答案
int isBST(struct node* node) {
if (node==NULL) return(true);
// false if the max of the left is > than us
// (bug -- an earlier version had min/max backwards here)
if (node->left!=NULL && maxValue(node->left) > node->data)
return(false);
// false if the min of the right is <= than us
if (node->right!=NULL && minValue(node->right) <= node->data)
return(false);
// false if, recursively, the left or right is not a BST
if (!isBST(node->left) || !isBST(node->right))
... 阅读全帖
p*****2
发帖数: 21240
7

5
4 8
2 7 9
3 10
我的想法是这样。
5是root
4是left tree
8是right tree
到4的时候数值范围是 Integer.MinValue - 5
左tree的范围 Integer,MinValue - 4
右tree的范围 4-5
这样你就知道2是左tree,这样recursion就可以了。
j********r
发帖数: 127
8
来自主题: JobHunting版 - Two CS interview questions
溢出啊,来回类型cast啊,而且逻辑也完全错误,
你代入Rand() = 0, 和Rand()= int.MinValue算一下
min + Rand() * (max - min) / (int.MaxValue - int.
MinValue + 1)
c******a
发帖数: 198
9
来自主题: JobHunting版 - Two CS interview questions
sorry, my solution was below. this one should be logically correct. (the
previous one had a typo.)
min + (Rand() - int.MinValue) * (max - min + 1) / (int.MaxValue - int.
MinValue + 1)
b****o
发帖数: 403
10
来自主题: Programming版 - 一个matlab问题
用 imshow(a, 'DisplayRange', [minvalue maxvalue]) 可以把一个grayscale图像显
示出来,像素值在minvalue和maxvalue的被线性转换为0-255的数值,超出范围的像素
值在两头分别被转换为0和255.
我的问题是,不自己编程,有没有现成的函数得到这个转换过后的图像内容?
先谢谢了
H*******r
发帖数: 98
11
来自主题: Statistics版 - 编程菜鸟问一个sas编程问题
one is...
data select;
set original;
where var1 in (value1 value2 value3 value4 value5 value6 value7 value8)
or
var1 between minvalue and maxvalue or
var2 in (number1 number2 number3) or
var3 in (number1 number2 number3) or
var4 in (number1 number2 number3) or
var5 in (number1 number2 number3) or
var6 in (number1 number2 number3) or
var7 in (number1 number2 number3) or
var8 in (number1 number2 number3) or
... 阅读全帖
m********5
发帖数: 619
12
你这个条件1和条件2我看着怎么重叠啊....
proc sql; create table data3 as select a.*, b.* from data1 as a, data2 as b
where a.var1=b.var1 and a.var2=b.var2 and a.date1-b.date2>=minvalue and a.
date1-b.date2>0;
quit;
m********5
发帖数: 619
13
你以为proc sql是机器人啊
你既然有dataset 3 containing a variable (minvalue)
你不告诉sas,sas怎么算
h********0
发帖数: 440
14
来自主题: JobHunting版 - 讨论个Binary search tree的题目
前面看到有一个贴子是判断isBinaryTree的问题
http://www.mitbbs.com/article_t/JobHunting/31521831.html
讨论结果主要有两个方向
(1) inOrderScan, 看看是不是结果排序了
(2) 对每一个节点判断是不是
node->val >= minValue(right tree)
node->val < maxValue(left tree)
对于第一种思路,我有一个问题,如果BST有重复值
BST assumes
left child <= current node < right child
但是如果我们只是看结果是不是排序,这个“=”就不知道在什么地方了
有可能是 for some node: left child < current node <=right child.
那即使结果是排序的,其实也是有问题。
我自己想可以用一些方法来检查,但是都很ugly. 所以不知道有没有什么更好的想法。
对于第二种思路,在上一个贴子里有提供一个链接
http://cslibrary.stanford
I**A
发帖数: 2345
15
这个我大致看过
int minValue(struct node* node) {
struct node* current = node;
/* loop down to find the leftmost leaf */
while (current->left != NULL) {
current = current->left;
}
return(current->data);
}
int maxValue(struct node* node) {
struct node* current = node;
/* loop down to find the leftmost leaf */
while (current->right != NULL) {
current = current->left;
}
return(current->data);
}
这俩function,肯定有一个有问题。。。
再说了,这样求max and min也不make sense,因为只要在保证left or right是BST的
情况下才能
s*******f
发帖数: 1114
16
using System;
using System.Collections.Generic;
using System.Text;
namespace MSC
{
class Program
{
//“bool F(string s, char ch1, char
ch2, int n)”
//The function determines whether
or not there exists an occurrence of
//ch1 and ch2 separated by a
distance of no more than n in the given
//string s, where s is ascii and
user entered (your function needs
//to work on any input.) The
function must be efficient and
//**optimized** for both space... 阅读全帖
e***s
发帖数: 799
17
来自主题: JobHunting版 - 微软onsite面经
//2. 不断从一个stream里读数据,找到最大的K个数。就是用一个大小为K的min-heap就
//好了。但是要求
//写code 实现min-heap的插入/删除操作。
public static void getKMaxNumber(int k)
{
int[] min_heap;
min_heap = new int[k + 1]; //min_heap[1] is root.
for (int i = 0; i <= k; i++)
min_heap[i] = int.MinValue;
while (true)
{
int n;
n = Convert.ToInt32(Console.ReadLine());
if(n > min_heap[1])
{
... 阅读全帖
c*********n
发帖数: 1371
18
来自主题: JobHunting版 - 问道关于快速找bucket的面试题
我觉得这个题的本质是在第一个数组A中,对第二个数组B中的每个
元素找最接近的两个数:
假设对space没有要求.
create arrays:
BLower[B.length]{int.minValue, ........},
BUpper[B.length]{int.maxValue, ........}
for each( a in A){
for( i from 0 to B.length-1)
{
if(a BLower[i]=a;
}
if(a>B[i] && BUpper[i]>a){
BUpper[i]=a;
}
}
}
return string[]{"[BLower[0], BUpper[0]", "[BLower[1], BUpper[1]",....."[
BLower[n-1], BUpper[n-1]"}

22]
string
p*****2
发帖数: 21240
19
来自主题: JobHunting版 - 问两道facebook面试题
第二题
int maxSum=int.MinValue;
Node maxTree=null;
int Find(Node* node)
{
if(node==null)
return 0;
int l=Find(node.left);
int r=Find(node.right);
int sum=l+r+node.value;
if(sum>maxSum)
{
maxTree=node;
maxSum=sum;
}
return sum;
}
p*****2
发帖数: 21240
20
来自主题: JobHunting版 - 问两道facebook面试题

没问题呀。输出都是-5.
using System;
using System.Text;
using System.Collections.Generic;
public class Node
{
public int value;
public Node left;
public Node right;
public Node(int v, Node l, Node r)
{
value = v;
left = l;
right = r;
}
}
public class MaxSum
{
public int maxSum = int.MinValue;
public Node maxTree = null;
public int Find(Node node)
{
if(node==null)
return 0;
int l=Find(node.left);
int r=Fi... 阅读全帖
l*****a
发帖数: 14598
21
来自主题: JobHunting版 - 问两道facebook面试题
-5 works
how about one node with int.MinValue
s******n
发帖数: 3946
22
来自主题: JobHunting版 - 问两道google题
第二题,就是搞2个Heap来实现。
Heap1:MaxHeap, Heap2:MinHeap,保持Heap1.size==Heap2.size或者Heap1.size==
Heap2.size+1
void addNum(int num) {
if (Heap1.size==Heap2.size+1) {
if (num<=Heap1.maxValue()) {
int heap1MaxValue = Heap1.pop();
Heap2.add(heap1MaxValue);
Heap1.add(num);
} else Heap2.add(num);
} else {
if (num>=Heap2.MinValue()) {
int heap2MinValue = Heap2.pop();
Heap1.add(heap2MinValue);
Heap2.add(num);
} else Heap1.add(num);
}
}
多个机器的问题:从每个机器读一个block过来,效率比较好
s******n
发帖数: 3946
23
来自主题: JobHunting版 - 问道G家算法题
class DataStructure {
protected:
deque q;
deque v;
public:
void push_back(int data)
{
while (v.size()>0) {
if (v.back()>data) v.pop_back();
else break;
}
q.push_back(data);
v.push_back(data);
}
int pop_front() {
int ret = q.pop_front();
if (ret==v.front()) v.pop_front();
return ret;
}
int size() {
return q.size();
}
int minValue() {
assert(v.size()>0);
return v.front();
}
}
y****n
发帖数: 743
24
来自主题: JobHunting版 - 两个整数除法的问题太刁钻了吧
如果不考虑正负和溢出,一行代码的事。
public static int Div(Int64 a, Int64 b, ref Int64 m)
{
return a >= b << 1 ? (Div(a, b << 1, ref m) << 1) + Div(m, b, ref m) : a
>= b ? (m = a - b) > 0 ? 1 : 1 : (m = a) > 0 ? 0 : 0;
}
public static Int64 Div(Int64 a, Int64 b)
{
if (b == 0)
throw new Exception("Div By 0");
else if ((a == Int64.MinValue) && (b == -1))
throw new Exception("Overflow");
bool neg = (Math.Sign(a) != Math.Sign(b));
Int64 mod = 0;
Int64 result = Div(a, b, ref mod... 阅读全帖
y****n
发帖数: 743
25
来自主题: JobHunting版 - 两个整数除法的问题太刁钻了吧
如果不考虑正负和溢出,一行代码的事。
public static int Div(Int64 a, Int64 b, ref Int64 m)
{
return a >= b << 1 ? (Div(a, b << 1, ref m) << 1) + Div(m, b, ref m) : a
>= b ? (m = a - b) > 0 ? 1 : 1 : (m = a) > 0 ? 0 : 0;
}
public static Int64 Div(Int64 a, Int64 b)
{
if (b == 0)
throw new Exception("Div By 0");
else if ((a == Int64.MinValue) && (b == -1))
throw new Exception("Overflow");
bool neg = (Math.Sign(a) != Math.Sign(b));
Int64 mod = 0;
Int64 result = Div(a, b, ref mod... 阅读全帖
r*c
发帖数: 167
26
来自主题: JobHunting版 - 问一道题(6)
之前写了个C#的。思路都一样, use tree matching algorithm to determine the
candidate window.
//using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
class MinWindowSolution
{
class TreeNode
{
public TreeNode parent;
public int val;
public List children;
public TreeNode(int i, TreeNode p) { val = i; parent = p; children =
new List(); }
};
public void FindMinWindow_Tree(int[] input, int[] query, out int nS... 阅读全帖
l******s
发帖数: 3045
27
来自主题: JobHunting版 - 请问一道关于binary tree的题
A recursive solution. Returning the max value while building the List
bigPath.
private int printBigNodePath(TreeNode root, List bigPath)
{
if (root == null) return int.MinValue;
bigPath.Add(root);
List curLeftPath = new List();
List curRightPath = new List();
int leftBig = printBigNodePath(root.Left, curLeftPath);
int rightBig = printBigNodePath(root.Right, curRightPath);
if (leftBig > rightBig && leftBig > root.Value)... 阅读全帖
h******e
发帖数: 52
28
来自主题: JobHunting版 - 请问一道关于binary tree的题
这个题需要用一个trick去记住当前相对与root的位置。
int max = int.MinValue, maxPos = 0;
Inorder(Node node, int pos)
{
if(node == null)
return;
Inorder(node.left, pos*2);
if(max < node.val)
{
max = node.val;
maxPos = pos;
}
Inorder(node.left, pos*2+1);
}
Now we get max and the maxPos associated with it.
Then divide the maxPos by 2 all the way to 0, for example,
maxPos = 25, we get
1<-3<-6<-12
r->r->l-l
save the array 1,3, 6, 12 and start from 1 and b... 阅读全帖
l******s
发帖数: 3045
29
private static int divideBy7(int num){
if (num == int.MinValue) return -divideBy7(int.MaxValue);
if (num < 0) return -divideBy7(-num);
int result = 0;
while (num >= 7){
int subResult = 1, div = 7;
while (((div << 3) | 7) > 0 && num >= ((div << 3) | 7)){
div = (div << 3) | 7;
subResult = subResult << 3 | 1;
}
while ((div << 1) > 0 && num >= (div << 1)){
div <<= 1; subResult <<= 1;
}
num -= div; res... 阅读全帖
c******a
发帖数: 198
30
来自主题: JobHunting版 - Two CS interview questions
is this also correct or wrong? if wrong, what are potential issues? thanks.
min + Rand() * (max - min + 1) / (int.MaxValue - int.
MinValue + 1)
c******a
发帖数: 198
31
来自主题: JobHunting版 - Two CS interview questions
i like your modulo idea. but your solution may also have an overflow issue,
when rand() returns int.MaxValue and min is int.MinValue.
i think this modified one should work without overflow.
return min + rand() % (max - min + 1);

发帖数: 1
32
来自主题: JobHunting版 - 贡献一个最近电面题目
static int[] findSub(int[] arr)
{
int[] result =new int[2];
int s=-1, e=-1,min=Int32.MaxValue,max=Int32.MinValue;
for (int i = 0; i < arr.Length-1; i++)
{
if (arr[i] > arr[i + 1])
{
s = i + 1;
break;
}
}
for (int i = arr.Length - 1;i>0; i--)
{
if (arr[i - 1] > arr[i])
{
... 阅读全帖
y***r
发帖数: 1845
33
发现附件不能贴程序。那就直接放这里吧。有兴趣的可以自己改改试试。
#### COPY START ####
# Reads log.xml exported from runningahead.com and analyzes the correlation
between the heart rate and pace.
#
# How to use this script:
#
# 1. Go to runningahead website, Training Log, Tools, click "Download
training data to your computer".
# 2. Select XML and click Download button.
# 3. Open the zip file and extract the log.xml to a folder.
# 4. In PowerShell console, go to the above folder and run ".\RA-
HeartRatePaceCorrelation.ps1 > data... 阅读全帖
f******y
发帖数: 14
34
来自主题: Database版 - Oracle序列使用问题!
使用VC++编程;
我建立一个序列,希望每次加1,
我在sql plus下执行
select SEQ_MESSAGE_MESSAGE_NUM.nextval from dual;
每次都是对的;
但在程序里面每次却加2,让我不理解;
序列创建:
CREATE SEQUENCE SEQ_MESSAGE_MESSAGE_NUM
INCREMENT BY 1
START WITH 1
MAXVALUE 1.0E28
MINVALUE 1
NOCYCLE
CACHE 20
ORDER;
程序:
ODatabase datab;
ODynaset dyn;
... ...
nOracleRet=dyn.Open(datab,"select
SEQ_MESSAGE_MESSAGE_NUM.nextval from dual");
int nNextVal;
dyn.GetFieldValue(0,&nNextVal);
dyn.Close();
... ...
CString szSql;
szSql.Format("Insert into Transmit_Message
(Message_Nu
1 (共1页)