Python interview with a Microsoft engineer: Max consecutive sequence

preview_player
Показать описание


Рекомендации по теме
Комментарии
Автор

wow, the interviewer is good. He may sound harsh, but I think he genuinely cares about the interviewee. I wish I had him as a coach lol

RoflcopterWosh
Автор

The interviewee needs to slow down and listen more

tolstoise
Автор

that was a long ass pause during the early minutes of the interview

damilolarandolph
Автор

This is valuable. Very tough question, and at first I thought the interviewer was harsh--but he ended up being an amazing interviewer that clear knows what he's doing. The interviewee is also very smart, but clearly has the difficulty we all face of being nervous.

BobbyMully
Автор

this is the kind of interviewer that would be a superb manager/tech lead. THIS is what you want from superiors, candor

rickyjoebobby
Автор

the interviewer gave a lot of good nudges in the right direction fairly early. not sure if this is realistic to expect, but i sure wouldn't mind being interviewed like this

laffed
Автор

In the lines of 24 and 30, there are bugs since looking the index by the value of itself is meaningless. It will give error in the line 24 when it comes to 99 in the array since visited[99] gives out of bounds exception. There should be a kind of hashmap to take the indexes

melihunsal
Автор

A clear thinking approach should something like this:

store in hash

loop items
check visisted
while (going lower till not found) +1
while (going higher till not found) +1

update max if needed
end

return max

michaeldang
Автор

The interviewer is really good..I haven't encountered such detailed feedback and hints roadmap till now

rituraj
Автор

This problem is easier to look at if you just put the values in a dictionary, it only checks each value once, and then you basically run it the same...keep track of the maximum count, or keep counts in a list and return the maximum...

jamesbondisamonkey
Автор

Should the "visited[forward]" and "visited[backward]" be the index where forward and backward are found in the arr_set? Otherwise it'll go out of bounce when it tries "visited[99]" right?

randomkoolstuff
Автор

class Solution:
def longestConsecutive(self, nums: List[int]) -> int:

if len(nums)<=1:
return len(nums)

tmp = set(nums)
nums = list(tmp)
nums.sort()

maxTest = 0
tmpNum = 1
for i in range(len(nums) - 1):
if nums[i] == nums[i+1] - 1:
tmpNum = tmpNum + 1
else:
if tmpNum > maxTest:
maxTest = tmpNum
tmpNum = 1

return max(maxTest, tmpNum)

(This is how I approached it, but I have only taken a simple intro course)

VipulPeriwal
Автор

Thanks for posting man, very few people would post such an interview, keep it up 😇, and waiting for your winning interview

MohammedBakheet
Автор

So, this is a hard question on LeetCode. And what if someone solves this question without the need of nay help, I assume, it is because they have solved it before and didn't come up with the approach right away. So would it be a positive point for the candidate if she/he solves it without any help?

gsb
Автор

He needed to slow down and think about the implementation before coding everything. A lot of the comments say the interviewer shouldn't have interrupted him, but if he didn't, the interviewee would have ended up with a 10x buggier implementation that would have taken 2h to debug.

zhjttly
Автор

def extract_max_seq(arr):
seq = sorted(set(arr))

ls, final = [], []
for i in range(len(seq)):
ls.append(seq[i])

if i == len(seq)-1 or seq[i+1] - seq[i] != 1:
final.append(ls)
ls = []

return final

pranjalpathak
Автор

That was one of the good interviews with a good quality feedback, I've ever seen.

Apart from that, this question could be done with much less complexity if the coder has used hashmaps, simply by putting the array elements into hashmap and set the value of key = 0( marking them non-visited) and in the forward and the backward loop, if the next consecutive element is available in the keys of hashmap, do "arr_hashmap[ele]=1(mark it visited)"

nikhilchawla
Автор

The interviewer seems to be a good guy.
Some times all they try for is to make the candidate feel worthless and to make him hate himself.

innopark
Автор

C .
As you can see it is real to use only one while loop.
int MaxLenghtOfConsecutive(int a[], int size){

int count = 0, next, max = 0;
int visited[101] = {0}, save[101] = {0};


for(int i = 0; i < size; i++) save[a[i]] = 1;

for(int i = 0; i < size; i++)
{
if( visited[a[i]] ) continue;
visited[a[i]] = 1;
count++;
next = a[i] + 1;

while(save[next])
{
visited[next] = 1;
count++;
next++;
}
if(count == size) return count;
max = ( (count > max ) ? count : max );
count = 0;
}

return max;
}

dav
Автор

def longestConsecutive(self, nums: List[int]) -> int:
maxStreak = 0
setNums = set(nums)

for i in nums:
if i - 1 not in nums:
currentStreak = 1
while i + 1 in nums:
currentStreak += 1
i = i + 1
maxStreak = max(maxStreak, currentStreak)

return maxStreak

xNamsu
join shbcf.ru