"MOD = 10**9 + 7
def max_stability(reliability, availability):
max_stability = 1
for r, a in zip(reliability, availability):
Compute stability of the current server
stability = r * a
if stability != 0:
Multiply into max_stability and take modulo
maxstability = (maxstability * stability) % MOD
return max_stability
reliability = [1, 2, 2]
availability = [1, 1, 3]
print(max_stability(reliability, availability)) # Output the result mo"
K.nithish K. - "MOD = 10**9 + 7
def max_stability(reliability, availability):
max_stability = 1
for r, a in zip(reliability, availability):
Compute stability of the current server
stability = r * a
if stability != 0:
Multiply into max_stability and take modulo
maxstability = (maxstability * stability) % MOD
return max_stability
reliability = [1, 2, 2]
availability = [1, 1, 3]
print(max_stability(reliability, availability)) # Output the result mo"See full answer
"SELECT d.name as departmentname,e.id as employeeid,e.firstname,e.lastname,MAX(e.salary) as salary
FROM employees e LEFT JOIN departments d
ON e.department_id=d.id
GROUP BY department_name
ORDER BY department_name;"
Anisha S. - "SELECT d.name as departmentname,e.id as employeeid,e.firstname,e.lastname,MAX(e.salary) as salary
FROM employees e LEFT JOIN departments d
ON e.department_id=d.id
GROUP BY department_name
ORDER BY department_name;"See full answer
"First thing the interviewee did wrong is not asking clarifying questions. This is the most vague problem I have every heard, and the interviewee just made assumptions and started programming."
Nicholas S. - "First thing the interviewee did wrong is not asking clarifying questions. This is the most vague problem I have every heard, and the interviewee just made assumptions and started programming."See full answer
"def mostefficientseqscore(parentheses, efficiencyratings):
mes = []
for i in range(len(parentheses)):
mes.append((parentheses[i], max(efficiency_ratings[i]))
return sum([m[1] for m in mes])
`"
Nathan C. - "def mostefficientseqscore(parentheses, efficiencyratings):
mes = []
for i in range(len(parentheses)):
mes.append((parentheses[i], max(efficiency_ratings[i]))
return sum([m[1] for m in mes])
`"See full answer
"we can use two pointer + set like maintain i,j and also insert jth character to set like while set size is equal to our window j-i+1 then maximize our answer and increase jth pointer till last index"
Kishor J. - "we can use two pointer + set like maintain i,j and also insert jth character to set like while set size is equal to our window j-i+1 then maximize our answer and increase jth pointer till last index"See full answer
"A recursive backtracking solution in python.
def changeSigns(nums: List[int], S: int) -> int:
res = []
n = len(nums)
def backtrack(index, curr, arr):
if curr == S and len(arr) == n:
res.append(arr[:])
return
if index >= len(nums):
return
for i in range(index, n):
add +ve number
arr.append(nums[i])
backtrack(i+1, curr + nums[i], arr)
arr.pop()
"
Yugaank K. - "A recursive backtracking solution in python.
def changeSigns(nums: List[int], S: int) -> int:
res = []
n = len(nums)
def backtrack(index, curr, arr):
if curr == S and len(arr) == n:
res.append(arr[:])
return
if index >= len(nums):
return
for i in range(index, n):
add +ve number
arr.append(nums[i])
backtrack(i+1, curr + nums[i], arr)
arr.pop()
"See full answer
"SELECT
u.user_id,
u.user_name,
u.email,
ROUND(AVG(CASE WHEN b.status = 'Unmatched' THEN 1.0 ELSE 0 END), 2) AS avgunmatchedbookings
FROM
users u
LEFT JOIN
bookings b ON u.userid = b.userid
GROUP BY
u.user_id,
u.user_name,
u.email;
`"
Akshay D. - "SELECT
u.user_id,
u.user_name,
u.email,
ROUND(AVG(CASE WHEN b.status = 'Unmatched' THEN 1.0 ELSE 0 END), 2) AS avgunmatchedbookings
FROM
users u
LEFT JOIN
bookings b ON u.userid = b.userid
GROUP BY
u.user_id,
u.user_name,
u.email;
`"See full answer
"Abstract class
A class that can have Abstract methods - without implementations and Concerete Methods i.e with implementation.
Can have private, protected and public access modifiers.
Supports Single inheritance i.e a class can extend only 1 abstract class
Can have constructors
Mainly used when sharing common behaviors
Interface Class
A collection of abstract methods ( can have static and default methods also - onwards of java 8)
Public, static, final are the access"
Sue G. - "Abstract class
A class that can have Abstract methods - without implementations and Concerete Methods i.e with implementation.
Can have private, protected and public access modifiers.
Supports Single inheritance i.e a class can extend only 1 abstract class
Can have constructors
Mainly used when sharing common behaviors
Interface Class
A collection of abstract methods ( can have static and default methods also - onwards of java 8)
Public, static, final are the access"See full answer
"#inplace reversal without inbuilt functions
def reverseString(s):
chars = list(s)
l, r = 0, len(s)-1
while l < r:
chars[l],chars[r] = chars[r],chars[l]
l += 1
r -= 1
reversed = "".join(chars)
return reversed
"
Anonymous Possum - "#inplace reversal without inbuilt functions
def reverseString(s):
chars = list(s)
l, r = 0, len(s)-1
while l < r:
chars[l],chars[r] = chars[r],chars[l]
l += 1
r -= 1
reversed = "".join(chars)
return reversed
"See full answer
"Required output in the solution not the one requested from the question. only customerid, firstname, last_name and years were required. Please this needs to be very clear.
Otherwise my answer is
with totalorderyear as (
SELECT
o.customer_id,
c.first_name,
c.last_name,
EXTRACT(YEAR FROM o.orderdate) AS orderyear,
COUNT(o.orderid) AS totalorders
FROM orders o
LEFT JOIN customers c
ON c.customerid = o.customerid
GROUP BY o.customerid, c.firstname, c.last"
Gloriose H. - "Required output in the solution not the one requested from the question. only customerid, firstname, last_name and years were required. Please this needs to be very clear.
Otherwise my answer is
with totalorderyear as (
SELECT
o.customer_id,
c.first_name,
c.last_name,
EXTRACT(YEAR FROM o.orderdate) AS orderyear,
COUNT(o.orderid) AS totalorders
FROM orders o
LEFT JOIN customers c
ON c.customerid = o.customerid
GROUP BY o.customerid, c.firstname, c.last"See full answer
"I used array to append. np.array does not have append and every np.vstack recreates object again.
import numpy as np
class Centroid:
def init(self, location, vectors):
self.location = location # (D,)
self.vectors = vectors # (N_i, D)
class KMeans:
def init(self, n_features, k):
self.nfeatures = nfeatures
self.centroids = [
Centroid(
location=np.random.randn(n_features),
vectors=[] # I"
Dinar M. - "I used array to append. np.array does not have append and every np.vstack recreates object again.
import numpy as np
class Centroid:
def init(self, location, vectors):
self.location = location # (D,)
self.vectors = vectors # (N_i, D)
class KMeans:
def init(self, n_features, k):
self.nfeatures = nfeatures
self.centroids = [
Centroid(
location=np.random.randn(n_features),
vectors=[] # I"See full answer
"Let me try to explain it with simple life analogy
You're cooking dinner in the kitchen. Multithreading is when you've got a bunch of friends helping out. Each friend does a different job—like one chops veggies while another stirs a sauce. Everyone focuses on their task, and together, you all make the meal faster.
In a computer, it's like different jobs happening all at once, making stuff happen quicker, just like having lots of friends helping makes dinner ready faster."
Praveen D. - "Let me try to explain it with simple life analogy
You're cooking dinner in the kitchen. Multithreading is when you've got a bunch of friends helping out. Each friend does a different job—like one chops veggies while another stirs a sauce. Everyone focuses on their task, and together, you all make the meal faster.
In a computer, it's like different jobs happening all at once, making stuff happen quicker, just like having lots of friends helping makes dinner ready faster."See full answer
"You can ask some clarifying questions like
1) Ask if the list is already sorted or not
2) is zero included in the list ?
3) Natural numbers are usually positive numbers ( clarify they are non negatives)
Solution :
1) If sorted use two pointers and sort them in O(N)
2) if not sorted , -ve / only +ve numbers in the list doesn't matter - the easiest solution is
Use a priority queue and push the number and its square in each iteration
Finally return the list returned by the priority Queue. N"
Bless M. - "You can ask some clarifying questions like
1) Ask if the list is already sorted or not
2) is zero included in the list ?
3) Natural numbers are usually positive numbers ( clarify they are non negatives)
Solution :
1) If sorted use two pointers and sort them in O(N)
2) if not sorted , -ve / only +ve numbers in the list doesn't matter - the easiest solution is
Use a priority queue and push the number and its square in each iteration
Finally return the list returned by the priority Queue. N"See full answer
"python:
def justifywords(wordslist, width):
result = []
currlinechar_count = 0
curr_words = []
for word in words_list:
if curr_words:
space_needed = len(word) + 1 # Space needed for the word and a preceding space
else:
space_needed = len(word)
if currlinecharcount + spaceneeded > width:
result.append(' '.join(curr_words))
curr_words = [word]
currlinechar_count = len("
Anonymous Unicorn - "python:
def justifywords(wordslist, width):
result = []
currlinechar_count = 0
curr_words = []
for word in words_list:
if curr_words:
space_needed = len(word) + 1 # Space needed for the word and a preceding space
else:
space_needed = len(word)
if currlinecharcount + spaceneeded > width:
result.append(' '.join(curr_words))
curr_words = [word]
currlinechar_count = len("See full answer
"public class CircularBuffer {
private T[] buffer;
private int head;
private int tail;
private int size;
private final int capacity;
public CircularBuffer(int capacity) {
this.capacity = capacity;
this.buffer = (T[]) new Object[capacity];
this.head = 0;
this.tail = 0;
this.size = 0;
}
public void enqueue(T item) {
if (isFull()) {
throw new IllegalStateException("Buffer is full");
}
buf"
Vidhyadhar V. - "public class CircularBuffer {
private T[] buffer;
private int head;
private int tail;
private int size;
private final int capacity;
public CircularBuffer(int capacity) {
this.capacity = capacity;
this.buffer = (T[]) new Object[capacity];
this.head = 0;
this.tail = 0;
this.size = 0;
}
public void enqueue(T item) {
if (isFull()) {
throw new IllegalStateException("Buffer is full");
}
buf"See full answer