One of the strangest experiences I've had. Maybe I dogged a bullet.
The interviewer was nice and helpful.
It started with a behavioral question.
Tell me about a time you had a disagreement at work.
-I responded with the STAR method.
Then we moved on to the coding.
The coding problem was simple and to the point. I solved the question in what I thought was optimal. I discussed the complexity time/space.
I sent the interviewer a LinkedIn connection request with a message right after the interview.
Unfortunately, I got an email from the recruiter with a generic rejection. First time getting a "No" at the screening phase. FML
--Posting the question incase it helps someone in the spirit of open source.
Let’s say you are parsing posts and messages sent each day on a popular online community. Each day you get a report like this:
2021-01-01 12:00:23 [user2] a very long message a very long message a very long message a very long message a very long message a very long message a very long message a very long message a very long message a very long message a very long message a very long message a very long message a very long message a very long message a very long message
2021-01-01 12:00:23 [user3] blah blah blah blah blah blah blah blah blah blah
2021-01-01 12:00:23 [user4] blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
2021-01-01 12:00:23 [user1] blah blah blah blah
2021-01-01 12:00:23 [user2] blah blah
2021-01-01 12:00:23 [user5] blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
2021-01-01 12:00:23 [user6] blah blah blah blah blah blah blah blah blah blah
2021-01-01 12:00:23 [user2] blah blah blah blah blah blah blah blah
2021-01-01 12:00:23 [user7] blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
2021-01-01 12:00:23 [user8] blah blah blah blah blah blah blah blah blah blah blah blah blah Write a function that, given a number K, returns the K users who said the most words in the community.
import heapq
def parse(doc , k):
lookup = defaultdict(int)
lines = doc.split('\n')
for line in lines:
tokens = line.split(' ')
#[2021-01-01, 12:00:23, [user1], a, very, short, message]
lookup[tokens[2]] += len(tokens[3:])
print(lookup)
rank = []
for user, word_count in lookup.items():
heapq.heappush(rank,(word_count, user))
if len(rank) > k:
heapq.heappop(rank)
answer = []
for _ in range(k):
user = heapq.heappop(rank)
answer.append(user[1])
return answer[::-1]
#input_str = "2021-01-01 12:00:23 [user1] a very short message
k = 3
print(parse(input_str , k))