"Let’s say the matrix is m x n (i.e., m rows and n columns).
Start from the top-right corner of the matrix.
Move left if you see a 1.
Move down if you see a 0.
Keep track of the row index where you last saw the leftmost 1 — that row has the most 1s.
public class MaxOnesRow {
public static int rowWithMostOnes(int matrix) {
int rows = matrix.length;
int cols = matrix[0].length;
int maxRowIndex = -1;
int j = cols - 1; /"
Khushbu R. - "Let’s say the matrix is m x n (i.e., m rows and n columns).
Start from the top-right corner of the matrix.
Move left if you see a 1.
Move down if you see a 0.
Keep track of the row index where you last saw the leftmost 1 — that row has the most 1s.
public class MaxOnesRow {
public static int rowWithMostOnes(int matrix) {
int rows = matrix.length;
int cols = matrix[0].length;
int maxRowIndex = -1;
int j = cols - 1; /"See full answer
"Select
interface,
Count(case when issuccessfulpost then 1 end) as post_success,
Count() as postattempt,
ROUND((COUNT(CASE WHEN issuccessfulpost THEN 1 END) * 100 / COUNT()), 2) AS postsuccess_rate
from post where interface like 'Iphone%'
group by 1
order by postsuccessrate desc
`"
Richard B. - "Select
interface,
Count(case when issuccessfulpost then 1 end) as post_success,
Count() as postattempt,
ROUND((COUNT(CASE WHEN issuccessfulpost THEN 1 END) * 100 / COUNT()), 2) AS postsuccess_rate
from post where interface like 'Iphone%'
group by 1
order by postsuccessrate desc
`"See full answer
"https://www.geeksforgeeks.org/find-local-minima-array/
I coded O(N) but after that gave a binary approach aswell.
After that he also gave a varient of this problem in which, local minima means that the number is strictly less than its adjacent (we cannot do binary search there sample test case [1,1,1,1,1,1,0,1] or [1,0,1,1,1,1,1,1] using mid we cannot determine if the minima is on left or right). we have to do a linear search or find recursively."
Anonymous Porcupine - "https://www.geeksforgeeks.org/find-local-minima-array/
I coded O(N) but after that gave a binary approach aswell.
After that he also gave a varient of this problem in which, local minima means that the number is strictly less than its adjacent (we cannot do binary search there sample test case [1,1,1,1,1,1,0,1] or [1,0,1,1,1,1,1,1] using mid we cannot determine if the minima is on left or right). we have to do a linear search or find recursively."See full answer
"Was given 90 minutes with an exhaustive set of requirements to be implemented as a full-stack coding exercise. It was supposed to have a UX, a server and a database to store and retrieve data.
The IDE was supposed to be self-setup before the interview.
The panel asked questions on top of the implementation around decision making from a technical perspective"
Aman G. - "Was given 90 minutes with an exhaustive set of requirements to be implemented as a full-stack coding exercise. It was supposed to have a UX, a server and a database to store and retrieve data.
The IDE was supposed to be self-setup before the interview.
The panel asked questions on top of the implementation around decision making from a technical perspective"See full answer
"Here is my first shot at it. Please excuse formatting.
To find the maximum depth of the dependencies given a list of nodes, each having a unique string id and a list of subnodes it depends on, you can perform a depth-first search (DFS) to traverse the dependency graph. Here's how you can implement this:
Represent the nodes and their dependencies using a dictionary.
Perform a DFS on each node to find the maximum depth of the dependencies.
Keep track of the maximum depth encountered dur"
Tes d H. - "Here is my first shot at it. Please excuse formatting.
To find the maximum depth of the dependencies given a list of nodes, each having a unique string id and a list of subnodes it depends on, you can perform a depth-first search (DFS) to traverse the dependency graph. Here's how you can implement this:
Represent the nodes and their dependencies using a dictionary.
Perform a DFS on each node to find the maximum depth of the dependencies.
Keep track of the maximum depth encountered dur"See full answer
"WITH high_score AS(
SELECT
player_id,
MAX(gamescore) AS maxscore
FROM scores
GROUP BY player_id
),
rankings AS(
SELECT
p.player_name,
p.team_id,
max_score,
DENSERANK() OVER(PARTITION BY p.teamid ORDER BY h.maxscore DESC) AS scorerank
FROM high_score AS h
JOIN players AS p
USING(player_id)
)
SELECT
team_id,
player_name,
max_score
FROM rankings
WHERE score_rank <= 2
GROUP BY teamid, playername
O"
Alvin P. - "WITH high_score AS(
SELECT
player_id,
MAX(gamescore) AS maxscore
FROM scores
GROUP BY player_id
),
rankings AS(
SELECT
p.player_name,
p.team_id,
max_score,
DENSERANK() OVER(PARTITION BY p.teamid ORDER BY h.maxscore DESC) AS scorerank
FROM high_score AS h
JOIN players AS p
USING(player_id)
)
SELECT
team_id,
player_name,
max_score
FROM rankings
WHERE score_rank <= 2
GROUP BY teamid, playername
O"See full answer
"public static void sortBinaryArray(int[] array) {
int len = array.length;
int[] res = new int[len];
int r=len-1;
for (int value : array) {
if(value==1){
res[r]= 1;
r--;
}
}
System.out.println(Arrays.toString(res));
}
`"
Nitin P. - "public static void sortBinaryArray(int[] array) {
int len = array.length;
int[] res = new int[len];
int r=len-1;
for (int value : array) {
if(value==1){
res[r]= 1;
r--;
}
}
System.out.println(Arrays.toString(res));
}
`"See full answer
"Problem: Given a modified binary tree, where each node also has a pointer to it's parent, find the first common ancestor of two nodes.
Answer: As it happens, the structure that we're looking at is actually a linked list (one pointer up), so the problem is identical to trying to find if two linked lists share a common node.
How this works is by stacking the two chains of nodes together so they're the same length.
chain1 = node1
chain2= node2
while True:
chain1 = chain1.next
chain2=chain"
Michael B. - "Problem: Given a modified binary tree, where each node also has a pointer to it's parent, find the first common ancestor of two nodes.
Answer: As it happens, the structure that we're looking at is actually a linked list (one pointer up), so the problem is identical to trying to find if two linked lists share a common node.
How this works is by stacking the two chains of nodes together so they're the same length.
chain1 = node1
chain2= node2
while True:
chain1 = chain1.next
chain2=chain"See full answer
"def validateIP(ip):
"""
@param ip: str
@return: bool
"""
\# ip needs to be in X.X.X.X
\# X is from 0 to 255
\# split the ip at "."
split = ip.split('.')
if (len(split) != 4):
return False
for number in split:
if (int(number) 255):
return False
return True"
Anonymous Owl - "def validateIP(ip):
"""
@param ip: str
@return: bool
"""
\# ip needs to be in X.X.X.X
\# X is from 0 to 255
\# split the ip at "."
split = ip.split('.')
if (len(split) != 4):
return False
for number in split:
if (int(number) 255):
return False
return True"See full answer
"Here is my implementation:
select
marketing_channel,
AVG(purchasevalue) as avgpurchase_value
from
attribution
group by marketing_channel
order by avgpurchasevalue DESC
;
There is no need to copy and past the line of code for calculating the average into order by, just Alias is enough because going by the order of execution in sql, Always, order by is executed after executing select clause."
Maliki U. - "Here is my implementation:
select
marketing_channel,
AVG(purchasevalue) as avgpurchase_value
from
attribution
group by marketing_channel
order by avgpurchasevalue DESC
;
There is no need to copy and past the line of code for calculating the average into order by, just Alias is enough because going by the order of execution in sql, Always, order by is executed after executing select clause."See full answer
"select
sub.name subreddit_name,
count(distinct us.userid) totalusers
from user_subreddit as us
left join subreddit as sub
on us.subredditid = sub.subredditid
group by
us.subreddit_id
having
count(distinct us.user_id) > 3"
Lucas G. - "select
sub.name subreddit_name,
count(distinct us.userid) totalusers
from user_subreddit as us
left join subreddit as sub
on us.subredditid = sub.subredditid
group by
us.subreddit_id
having
count(distinct us.user_id) > 3"See full answer
"Should this question be BST, not just BT? Otherwise it would not be possible to reconstruct the tree solely based on the array regardless of its order"
TreeOfWisdom - "Should this question be BST, not just BT? Otherwise it would not be possible to reconstruct the tree solely based on the array regardless of its order"See full answer