↳
If you group by parent_id, you'll be leaving out all posts with zero comments.
↳
@ RLeung shouldn't you use left join? You are effectively losing all posts with zero comment. Moins
↳
Here is the solution. You need a left self join that accounts for posts with zero comments. Select children , count(submission_id) from ( Select a.submission_id, count(b.submission_id) as children from Submissions a Left Join submissions b on On a.submission_id=b.parent_id Where a.parent_id is null Group by a.submission_id ) a Group by children Moins
↳
the answer to the first question is - 1/3 + 1/3*1/2 = 1/2 the answer to the second question require the formula of conditional probability. Let's say: P(A) - probability that second stall is occupied P(B) - probability that the first stall is occupied P(A\B) = P(AandB) / P(B) P(B) = 1/2 (first question) P(AandB) = 1/3 P(A\B) = (1/3) / (1/2) = 2/3 Moins
↳
Above answer is wrong, the answer to the first and second question are both 1/2.
↳
there are 2 doors (A and B) and related 4 options with given probabilities option 1: A is full ; B is full ; prob 1/3 option 2: A is full; B is empty; prob "m" option 3: A is empty; B is full; prob "n" option 4: A is empty, B is empty, prob 1/3 we know m +n = 1/3 First question I have p1 probability to chose A and 1-p1 probability to chose B * I chose A and A is full: prob = 1/3+m * I chose B and B is full: prob = 1/3+n -> all together p1 *(1/3+m) + (1-p1)(1/3+n) -> assuming p1 =1/2 (probability of choosing door A and B equal) this gives 1/2 by using m+n = 1/3 Second question I chose door A first; prob of it being full is (1/3+a); given it is full we have 2 options "1" and "2". * Given A full being B is full (1/3)(1/3+a) * Given B full being A is full (1/3)(1/3+b) = (1/3)(1/3+(1/3-a)) then the total prob will be p1 * (1/3)(1/3+a) + (1-p1)(1/3)(1/3+(1/3-a)) if p1 =1/2 doors are not different in prob to be full if a=b = 1/6 choosing doors by the person is equally probable then this equation give 2/3 say door a is closer to the concert hall and b never gets full if A is empty and you always test B first; than p1 = 0; a = 1/3; b = 0 than If you find B full don't test A because the equation gives 1 Moins
↳
Interpret the question this way: we want to choose an N such that P_hat is an element of [P - delta, P + delta] with probability 95%. First, note that since P_hat is the sum of N Bernoulli trials with some common parameter (by assumption) that we are trying to estimate, we can safely assume P_hat to be normally distributed with mean equal to the true mean (P) and variance equal to (P)(1 - P) / N. Now, we when does a normally distributed random variable fall within delta of it's mean with 95% probability? The answer depends on how big delta is. Since P_hat is normally distributed, we know from our statistics classes that 95% of the time it will fall within 2 standard deviations of its mean. So in other words, we want [P - delta, P + delta] = [P - 2*SE(P_hat), P + 2*SE(P_hat)]. That is, we want delta = SE(P_hat). So what is the SE ("standard error") of P_hat? Well that's just the square root of its (sample) variance, or Sqrt(P_hat * (1 - P_hat) / N). But wait! We haven't run the experiment yet! How can we know what P_hat is? We can either (a) make an educated guess, or (b) take the "worst" possible case and use that to upper bound N. Let's go with option (b): P_hat * (1 - P_hat) is maximized when P_hat is .5, so the product is 0.25. To put it all together: delta = 2 * Sqrt(0.25) / Sqrt(N) = 2 * .5 / Sqrt(N) => N = (1 / delta) ^ 2. So when N is greater than (1 / delta)^2, we can rest assured that P_hat will fall within the acceptable range 95% of the time. Moins
↳
Use Chebyshev's inequality
↳
Rate has Poisson distribution, not Bernoulli. The mean equals the variance, SE = sqrt(P/N). Moins
↳
In Python: def normalize_length(str1, str2): len1 = len(str1) len2 = len(str2) if (len1 = 0): if (input2[i] == "1") and (input1[i] == "1"): if(carry): result = "1" + result carry = 1 else: carry = 1 result = "0" + result i -= 1 if (input2[i] == "1") and (input1[i] == "0"): if (carry): result = "0" + result else: result = "1" + result i -= 1 if (input2[i] == "0") and (input1[i] == "1"): if (carry): result = "0" + result else: result = "1" + result i -=1 if (input2[i] == "0") and (input1[i] == "0"): if (carry): result = "1" + result carry = 0 else: result = "0" + result i -=1 if(carry): result = "1" + result carry = 0 return(result) str1 = "111" str2 = "1011" print(normalize_length(str1, str2)) print(add_binary(str1, str2)) Obviously there are better ways to do this, but hey: my solution is O(N). Moins
↳
Ignore the answer above - didn't realize that Glassdoor would cut off parts of my answer for being too long. Assuming you already wrote the normalizing code to make the input lengths the same by adding zeros: def add_binary(input1, input2): normalized = normalize_length(input1, input2) input1 = normalized[0] input2 = normalized[1] length = len(input1) result = "" carry = 0 i = length-1 while(i >= 0): if (input2[i] == "1") and (input1[i] == "1"): if(carry): result = "1" + result carry = 1 else: carry = 1 result = "0" + result i -= 1 if (input2[i] == "1") and (input1[i] == "0"): if (carry): result = "0" + result else: result = "1" + result i -= 1 if (input2[i] == "0") and (input1[i] == "1"): if (carry): result = "0" + result else: result = "1" + result i -=1 if (input2[i] == "0") and (input1[i] == "0"): if (carry): result = "1" + result carry = 0 else: result = "0" + result i -=1 if(carry): result = "1" + result carry = 0 return(result) Moins
↳
def calc_bin_sum(bin1, bin2): ## bin1 conversion to a number based in 10 b1 = 0 for i in range(len(bin1)): b1 = b1 + int(bin1[i]) * (2**i) ## bin2 conversion to a number based in 10 b2 = 0 for j in range(len(bin2)): b2 = b2 + int(bin2[j]) * (2**i) ## Add two numbers corr_based_10 = b1 + b2 ## Change it back to binary def trans(x): binary = [] while x: binary.append(x % 2) x >>= 1 return binary return ''.join(map(str, trans(corr_based_10))) Moins
↳
A) what percent of active accounts are fraud? Select sum(Case when status = ‘fraud’ then 1 else 0 end)/count(*) as Fraud_percentage from ad_accounts where status ‘closed’; B) How many accounts became fraud today for the first time? select count(*) from ( select account_id, min(date) as First_fraud from ad_accounts where status = 'fraud' group by account_id having First_fraud = current_date() ); Moins
↳
Yep, should be A) what percent of active accounts are fraud? SELECT COUNT(DISTINCT t2.account_id)/COUNT( DISTINCT t1.account_id) AS perc_fraud FROM ad_accounts AS t1 LEFT JOIN ad_accounts AS t2 ON t1.account_id = t2.account_id AND t2.status = 'fraud' AND t2.date > t1.date WHERE t1.status = 'active' Moins
↳
For question B, if I assume i have today's data ans yesterday's data in the table, would this work? Select Count (distinct a.Account_id) From ad_accounts A Inner join ad_accounts b On a.account_id=b.account_id Where a.date=current_data and b.date=date_add (‘day’, -1, current_date) And a.status=’fraud’ And b.status!=’fraud’ Moins
↳
Group By
↳
Case statement
↳
NTILE window function
↳
What was your solution framed as? I'd be curious to know the alternatives you proposed and the possible assumptions that you made? Moins
↳
The interview was more like a "walk through a problem" discussion than an exams-type questionnaire which was a really fun and interesting experience. The talk was very casual (less stressful than usual) and felt as if we were colleagues working on an actual LinkedIn challenge. Moins
↳
I asked him why does he think these aspects of my private life should be discussed at this interview. Moins
↳
Hi, do not feel be insulted, GSK interview is behavior based interview, and I think they were trying to evaluate the relocation fee that you may need. Moins
↳
It's illegal for any hiring decision to be made based on marital status or children, so if you were really asked these questions you should report it to HR and the labor department. Moins
↳
1) ascending 2) null 3) join 4) aggregation
↳
Shouldn't no.4 be with SELECT statement? And optionally, aggregation
↳
Null
↳
For Postgres, Redshift & BigQuery: If this is a sum of rows for a column where 1 row is 19 and 1 row is null then the answer is 19. If this is straight up "Select 19 + null" then it's null Moins